Análisis de redes: Sistema de contratación del Estado (obras) y la relación entre municipalidades distritales en todo el departamento de Lima y las empresas ganadoras en el año 2023¶

Paso 1: Importamos nuestra data¶

In [16]:
!pip install -q openpyxl
In [17]:
import pandas as pd

lima_distritos = pd.read_excel("data/distritos_lima_final.xlsx", engine='openpyxl')

lima_distritos.head()
Out[17]:
Distritos ZRINCON_EIRL MIROVAL_SAC METACONTROL_SAC CORONEL_EJECUTORES WAR_SAC GIMAHU HUAYCHAOLA_SAC JAGIXA CONSTRUCTORA_DOLPHIN_SAC ... INVERSIONES_CAVIANDINA_SAC DAZER_CONSTRUCTION_SAC GRALAZ_SAC ECOTRAM_EIRL CORPORACION_INGENIERIA_Y_DESARROLLO_SAC W&W_CONSTRUCTORES_SAC GEOTEGG_SAC MAKI_ASOCIADOS_SAC COINVEFER_EIRL G&P_EL_ROBLE_SAC
0 Ate 1 2 4 2 1 1 3 1 1 ... 0 0 0 0 0 0 0 0 0 0
1 Barranco 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
2 Brena 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
3 Carabayllo 1 0 1 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0
4 Chorrillos 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0

5 rows × 445 columns

El Sistema de Contratación del Estado en el ámbito de obras públicas ha sido fundamental para establecer relaciones entre las municipalidades distritales del departamento de Lima y las empresas ganadoras en el año 2023. En nuestra base de datos, cada fila representa una municipalidad distrital, mientras que las columnas reflejan las empresas que obtuvieron contratos de obras. La asignación de valores en la matriz indica el número de obras ganadas por cada empresa: un valor de 1 indica que la empresa ganó una obra, un 2 indica dos obras, y un 0 señala que la empresa no obtuvo contratos en esa municipalidad. Esta estructura de datos permite analizar la distribución de contratos y evaluar la competencia entre las empresas en el contexto de las municipalidades, así como identificar patrones en la adjudicación de obras públicas en Lima durante este periodo.

Le damos un vistazo a nuestra base de datos¶

In [20]:
print(lima_distritos.dtypes)
Distritos                object
ZRINCON_EIRL              int64
MIROVAL_SAC               int64
METACONTROL_SAC           int64
CORONEL_EJECUTORES        int64
                          ...  
W&W_CONSTRUCTORES_SAC     int64
GEOTEGG_SAC               int64
MAKI_ASOCIADOS_SAC        int64
COINVEFER_EIRL            int64
G&P_EL_ROBLE_SAC          int64
Length: 445, dtype: object
In [22]:
print(lima_distritos['Distritos'].unique())
['Ate' 'Barranco' 'Brena' 'Carabayllo' 'Chorrillos' 'Cieneguilla' 'Comas'
 'El_Agustino' 'Independencia' 'La_Molina' 'La_Victoria' 'Lince'
 'Los_Olivos' 'Lurigancho(Chosica)' 'Lurin' 'Magdalena_del_Mar'
 'Miraflores' 'Pucusana' 'Puente_Piedra' 'Punta_Hermosa' 'Punta_Negra'
 'Rimac' 'San_Borja' 'San_Isidro' 'San_Juan_de_Lurigancho'
 'San_Juan_de_Miraflores' 'San_Luis' 'San_Martin_de_Porres' 'San_Miguel'
 'Santa_Anita' 'Santa_Maria_del_Mar' 'Santa_Rosa' 'Santiago_de_Surco'
 'Surquillo' 'Villa_El_Salvador' 'Villa_Maria_del_Triunfo' 'Paramonga'
 'Pativilca' 'Supe' 'Cajatambo' 'Arahuay' 'Santa_Rosa_de_Quives'
 'San_Vicente_de_Cañete' 'Asia' 'Cerro_Azul' 'Chilca' 'Imperial' 'Mala'
 'Quilmana' 'Santa_Cruz_de_Flores' 'Huaral' 'Aucallama' 'Chancay' 'Ihuari'
 'Santa_Cruz_de_Andamarca' 'Antioquia' 'Chicla' 'Huachupampa' 'Huanza'
 'Huarochiri' 'Ricardo_Palma' 'San_Antonio' 'Santiago_de_Anchucaya'
 'Santo_Domingo_de_los_Olleros' 'Surco(Huarochiri)' 'Huacho' 'Huaura'
 'Sayan' 'Vegueta' 'Hongos' 'Omas' 'Quinches' 'Tauripampa' 'Tupe'
 'Bellavista' 'La_Perla' 'La_Punta' 'Ventanilla' 'Mi_Peru']
In [24]:
print(lima_distritos.describe())
       ZRINCON_EIRL  MIROVAL_SAC  METACONTROL_SAC  CORONEL_EJECUTORES  \
count     79.000000    79.000000        79.000000           79.000000   
mean       0.101266     0.037975         0.113924            0.050633   
std        0.441296     0.250284         0.554408            0.272629   
min        0.000000     0.000000         0.000000            0.000000   
25%        0.000000     0.000000         0.000000            0.000000   
50%        0.000000     0.000000         0.000000            0.000000   
75%        0.000000     0.000000         0.000000            0.000000   
max        3.000000     2.000000         4.000000            2.000000   

         WAR_SAC     GIMAHU  HUAYCHAOLA_SAC     JAGIXA  \
count  79.000000  79.000000       79.000000  79.000000   
mean    0.012658   0.012658        0.088608   0.025316   
std     0.112509   0.112509        0.398390   0.158088   
min     0.000000   0.000000        0.000000   0.000000   
25%     0.000000   0.000000        0.000000   0.000000   
50%     0.000000   0.000000        0.000000   0.000000   
75%     0.000000   0.000000        0.000000   0.000000   
max     1.000000   1.000000        3.000000   1.000000   

       CONSTRUCTORA_DOLPHIN_SAC      JD&HN  ...  INVERSIONES_CAVIANDINA_SAC  \
count                 79.000000  79.000000  ...                   79.000000   
mean                   0.037975   0.012658  ...                    0.025316   
std                    0.192356   0.112509  ...                    0.225018   
min                    0.000000   0.000000  ...                    0.000000   
25%                    0.000000   0.000000  ...                    0.000000   
50%                    0.000000   0.000000  ...                    0.000000   
75%                    0.000000   0.000000  ...                    0.000000   
max                    1.000000   1.000000  ...                    2.000000   

       DAZER_CONSTRUCTION_SAC  GRALAZ_SAC  ECOTRAM_EIRL  \
count               79.000000   79.000000     79.000000   
mean                 0.025316    0.012658      0.012658   
std                  0.225018    0.112509      0.112509   
min                  0.000000    0.000000      0.000000   
25%                  0.000000    0.000000      0.000000   
50%                  0.000000    0.000000      0.000000   
75%                  0.000000    0.000000      0.000000   
max                  2.000000    1.000000      1.000000   

       CORPORACION_INGENIERIA_Y_DESARROLLO_SAC  W&W_CONSTRUCTORES_SAC  \
count                                79.000000              79.000000   
mean                                  0.037975               0.012658   
std                                   0.337526               0.112509   
min                                   0.000000               0.000000   
25%                                   0.000000               0.000000   
50%                                   0.000000               0.000000   
75%                                   0.000000               0.000000   
max                                   3.000000               1.000000   

       GEOTEGG_SAC  MAKI_ASOCIADOS_SAC  COINVEFER_EIRL  G&P_EL_ROBLE_SAC  
count    79.000000           79.000000       79.000000         79.000000  
mean      0.012658            0.012658        0.012658          0.012658  
std       0.112509            0.112509        0.112509          0.112509  
min       0.000000            0.000000        0.000000          0.000000  
25%       0.000000            0.000000        0.000000          0.000000  
50%       0.000000            0.000000        0.000000          0.000000  
75%       0.000000            0.000000        0.000000          0.000000  
max       1.000000            1.000000        1.000000          1.000000  

[8 rows x 444 columns]

Paso 2: Creamos una red bipartita¶

Una red bipartita es un tipo de estructura de red que se compone de dos conjuntos de nodos, donde las conexiones (o aristas) solo pueden existir entre nodos de diferentes conjuntos, y no dentro del mismo conjunto.

Antes que todo, establecemos nuestra columna "Distritos" como índice¶

In [28]:
lima_distritos.set_index('Distritos', inplace=True)
In [30]:
#Revisamos si existen valores perdidos
print(lima_distritos.isnull().sum())
ZRINCON_EIRL             0
MIROVAL_SAC              0
METACONTROL_SAC          0
CORONEL_EJECUTORES       0
WAR_SAC                  0
                        ..
W&W_CONSTRUCTORES_SAC    0
GEOTEGG_SAC              0
MAKI_ASOCIADOS_SAC       0
COINVEFER_EIRL           0
G&P_EL_ROBLE_SAC         0
Length: 444, dtype: int64

¡Ahora sí! Veamos el número de nodos y aristas¶

In [34]:
import networkx as nx

victoria = nx.Graph()  

municipalidades = lima_distritos.index.tolist()
victoria.add_nodes_from(municipalidades, bipartite=0)

empresas = lima_distritos.columns.tolist()
victoria.add_nodes_from(empresas, bipartite=1)

for distrito in lima_distritos.index:
    for empresa in lima_distritos.columns:
        if lima_distritos.loc[distrito, empresa] > 0:
            victoria.add_edge(distrito, empresa, weight=lima_distritos.loc[distrito, empresa])

print(f"Número de nodos: {victoria.number_of_nodes()}")
print(f"Número de aristas: {victoria.number_of_edges()}")
Número de nodos: 523
Número de aristas: 646

Paso 3: Análisis y visualización¶

Vemos las aristas y sus pesos respectivos¶

In [38]:
for edge in victoria.edges(data=True):
    print(edge)
('Ate', 'ZRINCON_EIRL', {'weight': 1})
('Ate', 'MIROVAL_SAC', {'weight': 2})
('Ate', 'METACONTROL_SAC', {'weight': 4})
('Ate', 'CORONEL_EJECUTORES', {'weight': 2})
('Ate', 'WAR_SAC', {'weight': 1})
('Ate', 'GIMAHU', {'weight': 1})
('Ate', 'HUAYCHAOLA_SAC', {'weight': 3})
('Ate', 'JAGIXA', {'weight': 1})
('Ate', 'CONSTRUCTORA_DOLPHIN_SAC', {'weight': 1})
('Ate', 'JD&HN', {'weight': 1})
('Ate', 'JUSAL_INVERSIONES', {'weight': 1})
('Ate', 'SIADEC_INGENIEROS_SAC', {'weight': 2})
('Ate', 'ENMANUEL&LUCIANO', {'weight': 1})
('Ate', 'VENTURO', {'weight': 1})
('Ate', 'HELICONIAS_DEL_HUALLAGA', {'weight': 1})
('Ate', 'LUCEMAR_EIRL', {'weight': 1})
('Ate', 'CASCINA', {'weight': 1})
('Ate', 'PJK', {'weight': 1})
('Barranco', 'NEBCAS_SAC', {'weight': 1})
('Barranco', 'LUMAYJE_SAC', {'weight': 3})
('Barranco', 'ESPINAR_SAC', {'weight': 1})
('Barranco', 'COSISE_CONSTRUCTORA', {'weight': 1})
('Barranco', 'INGEOBRAS_SAC', {'weight': 1})
('Barranco', 'GESTION&CONSTRUCCION_SAC', {'weight': 1})
('Barranco', 'CONSORCIO_MONTENEGRO', {'weight': 1})
('Brena', 'JJP_SAC', {'weight': 1})
('Brena', 'JJ_BYGGA', {'weight': 1})
('Brena', 'COPER', {'weight': 1})
('Brena', 'FKA', {'weight': 1})
('Carabayllo', 'ZRINCON_EIRL', {'weight': 1})
('Carabayllo', 'METACONTROL_SAC', {'weight': 1})
('Carabayllo', 'COPER', {'weight': 1})
('Carabayllo', 'COMAPORD_SAC', {'weight': 3})
('Carabayllo', 'ALTAS_CUMBRES', {'weight': 1})
('Carabayllo', 'JELY_CONTRATISTAS', {'weight': 1})
('Carabayllo', 'VACHAVEZ_SRL', {'weight': 4})
('Carabayllo', 'WCEX_EIRL', {'weight': 3})
('Carabayllo', 'EGUIZABAL', {'weight': 1})
('Carabayllo', 'AMIGARTE_PERU', {'weight': 1})
('Carabayllo', 'QUINAVAL', {'weight': 1})
('Carabayllo', 'GLOBAL_TRAKTOR', {'weight': 1})
('Carabayllo', 'FLAVIO', {'weight': 1})
('Carabayllo', 'WABS', {'weight': 1})
('Carabayllo', 'FALCON_SAC', {'weight': 1})
('Carabayllo', 'HELER', {'weight': 1})
('Carabayllo', 'OSERGEN_SAC', {'weight': 1})
('Carabayllo', 'YOMAR', {'weight': 1})
('Carabayllo', 'JACL', {'weight': 1})
('Carabayllo', 'COMPANY_SERVIS', {'weight': 1})
('Carabayllo', 'CONSTRUCTORA_TANOS', {'weight': 1})
('Carabayllo', 'CVV', {'weight': 1})
('Carabayllo', 'HT', {'weight': 1})
('Carabayllo', 'JHP', {'weight': 1})
('Chorrillos', 'JJP_SAC', {'weight': 2})
('Chorrillos', 'COPER', {'weight': 3})
('Chorrillos', 'FLAVIO', {'weight': 1})
('Chorrillos', 'FALCON_SAC', {'weight': 1})
('Chorrillos', 'JM_ARES', {'weight': 1})
('Chorrillos', 'AGREDA_GALLARDAY&JARA_SAC', {'weight': 2})
('Chorrillos', 'AMRO', {'weight': 1})
('Chorrillos', 'VSI', {'weight': 1})
('Chorrillos', 'DAMBEZ_COMPANY', {'weight': 1})
('Chorrillos', 'JARO', {'weight': 2})
('Chorrillos', 'BACA&TELLEZ', {'weight': 1})
('Chorrillos', 'NARDDY_EIRL', {'weight': 1})
('Chorrillos', 'JOMF_SRL', {'weight': 1})
('Chorrillos', 'GOLDEN', {'weight': 2})
('Chorrillos', 'GRUPO_V&ARQ', {'weight': 3})
('Chorrillos', 'C&C_SRL', {'weight': 1})
('Chorrillos', 'ALE_INGENIERIA&CONSTRUCCION', {'weight': 1})
('Chorrillos', 'TACTICAL_IT', {'weight': 1})
('Chorrillos', 'JFH', {'weight': 1})
('Chorrillos', 'AGS', {'weight': 1})
('Chorrillos', 'NANO', {'weight': 1})
('Chorrillos', 'VCP_CONSULTORES_Y_EJECUTORES', {'weight': 1})
('Chorrillos', 'EROVA_SAC', {'weight': 1})
('Chorrillos', 'MULTINEGOCIOS_KRISTEL', {'weight': 1})
('Cieneguilla', 'ZRINCON_EIRL', {'weight': 1})
('Cieneguilla', 'LEON_CONTRATISTAS', {'weight': 1})
('Cieneguilla', 'ALEJANDRO_CONTRATISTAS', {'weight': 1})
('Comas', 'ZRINCON_EIRL', {'weight': 2})
('Comas', 'CORONEL_EJECUTORES', {'weight': 1})
('Comas', 'SIADEC_INGENIEROS_SAC', {'weight': 1})
('Comas', 'NEBCAS_SAC', {'weight': 1})
('Comas', 'COPER', {'weight': 1})
('Comas', 'WCEX_EIRL', {'weight': 1})
('Comas', 'YOMAR', {'weight': 1})
('Comas', 'CVV', {'weight': 2})
('Comas', 'JARO', {'weight': 2})
('Comas', 'MARCOS_EIRL', {'weight': 2})
('Comas', 'INVERSIONES&JUVE_CORP', {'weight': 1})
('Comas', 'CONTRUCTORA_VALDIVIESO', {'weight': 2})
('Comas', 'THIMAR_GROUP', {'weight': 1})
('Comas', 'CCONST_J&L', {'weight': 2})
('Comas', 'CODENSA_SAC', {'weight': 1})
('Comas', '3G_CONSTRUCTORA', {'weight': 1})
('Comas', 'XIANY_SAC', {'weight': 1})
('El_Agustino', 'CORONEL_EJECUTORES', {'weight': 1})
('El_Agustino', 'COPER', {'weight': 1})
('El_Agustino', 'LEON_CONTRATISTAS', {'weight': 1})
('El_Agustino', 'CCONST_J&L', {'weight': 1})
('El_Agustino', 'INVERSIONES_MMG', {'weight': 2})
('El_Agustino', 'A&E_INVERSIONES', {'weight': 1})
('Independencia', 'GRUPO_JW', {'weight': 1})
('Independencia', 'ROAGA_SAC', {'weight': 1})
('Independencia', 'G&F_CONSTRUCTORA', {'weight': 1})
('Independencia', 'CORPORACION_JRO', {'weight': 1})
('Independencia', 'RASYR_CONSTRUCTORA', {'weight': 1})
('Independencia', 'INSERCO', {'weight': 1})
('La_Molina', 'JAEC_CONTRATISTAS', {'weight': 1})
('La_Molina', 'THE_MOON_CONTRATISTAS', {'weight': 2})
('La_Victoria', 'SABINA_CONTRATISTAS', {'weight': 1})
('La_Victoria', 'MONTALVO_CONSTRUCTORA', {'weight': 1})
('La_Victoria', 'BJL_CONSTRUCTORA', {'weight': 1})
('Lince', 'GMP_SAC', {'weight': 1})
('Los_Olivos', 'ESPINAR_SAC', {'weight': 2})
('Los_Olivos', 'EROVA_SAC', {'weight': 1})
('Los_Olivos', 'MONTALVO_CONSTRUCTORA', {'weight': 1})
('Los_Olivos', 'DASA_SAC', {'weight': 2})
('Los_Olivos', 'EXAGATEC_SAC', {'weight': 1})
('Los_Olivos', 'RANRA_SAC', {'weight': 1})
('Los_Olivos', 'CH&G_SAC', {'weight': 1})
('Los_Olivos', 'DUAL_DOOM', {'weight': 2})
('Los_Olivos', 'M&S_PROYECTS', {'weight': 2})
('Los_Olivos', 'MEJESA_SRL', {'weight': 1})
('Los_Olivos', 'RIBAB_EIRL', {'weight': 1})
('Los_Olivos', 'CAMEN_SAC', {'weight': 3})
('Los_Olivos', 'SPACIOZ_SAC', {'weight': 3})
('Los_Olivos', 'AJC_SAC', {'weight': 1})
('Los_Olivos', 'MALLQUI_SAC', {'weight': 1})
('Los_Olivos', 'CMM_SAC', {'weight': 1})
('Los_Olivos', 'CORPORACION_JARA_Y_CHAVEZ', {'weight': 1})
('Los_Olivos', 'CONINTEC_SRL', {'weight': 1})
('Los_Olivos', 'IGYCSAC', {'weight': 1})
('Lurigancho(Chosica)', 'HUAYCHAOLA_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'ESPINAR_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'INVERSIONES_MMG', {'weight': 1})
('Lurigancho(Chosica)', 'CORPORACION_LINARES_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'SAUCE_GRANDE', {'weight': 1})
('Lurigancho(Chosica)', 'CONSORCIO_NARANJALES', {'weight': 1})
('Lurigancho(Chosica)', 'VIKAC_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'CCOHIL_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'CHEC-FUN_CONSTRUCTORA', {'weight': 1})
('Lurigancho(Chosica)', 'C&D_SAC', {'weight': 2})
('Lurigancho(Chosica)', 'MVR_SAC', {'weight': 2})
('Lurigancho(Chosica)', 'GRUPO_H&S', {'weight': 1})
('Lurigancho(Chosica)', 'GA_SERVICES_SOLUTIONS', {'weight': 1})
('Lurigancho(Chosica)', 'PROGEN_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'INGENIERIA_Y_CONSTRUCCION GERAL', {'weight': 1})
('Lurigancho(Chosica)', 'EDCAVAR_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'ICM_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'JERUMI_EIRL', {'weight': 1})
('Lurigancho(Chosica)', 'CONCRETO_INKACON', {'weight': 1})
('Lurigancho(Chosica)', 'CHACHI_EIRL', {'weight': 1})
('Lurigancho(Chosica)', 'CARBAJAL_VICTOR', {'weight': 1})
('Lurigancho(Chosica)', 'SD_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'CONTRUCTORA_FERRO', {'weight': 1})
('Lurigancho(Chosica)', 'M&N_SRL', {'weight': 1})
('Lurigancho(Chosica)', 'ARCONST_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'NEPAL_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'TROMMEL_SAC', {'weight': 1})
('Lurigancho(Chosica)', 'SUAREZ_MANUEL', {'weight': 1})
('Lurigancho(Chosica)', 'EDIRESA_SAC', {'weight': 1})
('Lurin', 'GESTION&CONSTRUCCION_SAC', {'weight': 1})
('Lurin', '3G_CONSTRUCTORA', {'weight': 2})
('Lurin', 'XIANY_SAC', {'weight': 1})
('Lurin', 'JF_CONSTRUCTORES_SAC', {'weight': 1})
('Lurin', 'MULTISERVICIOS_INMOBILIARIA_PAOLA', {'weight': 1})
('Lurin', 'JOVE_WILLIAM', {'weight': 2})
('Lurin', 'JOVE&JOVE_SAC', {'weight': 1})
('Lurin', 'G_Y_J_SAC', {'weight': 1})
('Lurin', 'SEASAP_SAC', {'weight': 1})
('Lurin', 'OVLV_SAC', {'weight': 1})
('Magdalena_del_Mar', 'CONTRATISTAS_YOUNG_SAC', {'weight': 2})
('Magdalena_del_Mar', 'Y_M_SAC', {'weight': 3})
('Magdalena_del_Mar', 'MLM_SAC', {'weight': 1})
('Magdalena_del_Mar', 'OUR_HOUSE_CONSTRUCTION', {'weight': 1})
('Magdalena_del_Mar', 'LEXHIS_SAC', {'weight': 1})
('Magdalena_del_Mar', 'INGCONS_EIRL', {'weight': 1})
('Magdalena_del_Mar', 'HERCISA_SAC', {'weight': 1})
('Magdalena_del_Mar', 'ASFALTOS_Y_PAVIMENTOS_SAC', {'weight': 1})
('Miraflores', 'EROVA_SAC', {'weight': 1})
('Miraflores', 'HIGH_CONSTRUCTIONS', {'weight': 1})
('Miraflores', 'MULTINEGOCIOS_AARON_SAC', {'weight': 1})
('Miraflores', 'INCOT_SAC', {'weight': 1})
('Miraflores', 'CONSTRUCTORA_UPACA', {'weight': 1})
('Miraflores', 'CONSTRUCTORA_PERU_TRACTOR', {'weight': 1})
('Pucusana', 'DAED_SAC', {'weight': 1})
('Pucusana', 'INVERSIONES_HILARIO_SAC', {'weight': 1})
('Puente_Piedra', 'SIADEC_INGENIEROS_SAC', {'weight': 2})
('Puente_Piedra', 'VACHAVEZ_SRL', {'weight': 2})
('Puente_Piedra', 'CORPORACION_JARA_Y_CHAVEZ', {'weight': 1})
('Puente_Piedra', 'UDEL_EIRL', {'weight': 1})
('Puente_Piedra', 'LEVAZ_SAC', {'weight': 2})
('Punta_Hermosa', 'HUAYCHAOLA_SAC', {'weight': 1})
('Punta_Hermosa', 'GESTION&CONSTRUCCION_SAC', {'weight': 1})
('Punta_Hermosa', 'ALEJANDRO_CONTRATISTAS', {'weight': 1})
('Punta_Hermosa', 'JOVE_WILLIAM', {'weight': 1})
('Punta_Hermosa', 'AG_GROUP_EIRL', {'weight': 1})
('Punta_Hermosa', 'RASEC_EIRL', {'weight': 1})
('Punta_Negra', 'JROTRI_EIRL', {'weight': 1})
('Punta_Negra', 'HS_CONSTRUCTORA_INGENIEROS_SAC', {'weight': 1})
('Punta_Negra', 'HUASCARAN_SAC', {'weight': 1})
('Punta_Negra', 'TIERRA_SOL_SAC', {'weight': 1})
('Punta_Negra', 'JA&DE_SA', {'weight': 1})
('Rimac', 'JJP_SAC', {'weight': 1})
('Rimac', 'WCEX_EIRL', {'weight': 1})
('Rimac', 'FALCON_SAC', {'weight': 1})
('Rimac', 'MEJESA_SRL', {'weight': 1})
('Rimac', 'MALLQUI_SAC', {'weight': 1})
('Rimac', 'JROTRI_EIRL', {'weight': 1})
('Rimac', 'JA&DE_SA', {'weight': 1})
('Rimac', 'ROMAYSE_SAC', {'weight': 1})
('Rimac', 'OMZA_SAC', {'weight': 1})
('Rimac', 'MULTISERVIS_HH_EIRL', {'weight': 1})
('Rimac', 'VALENTINO_EIRL', {'weight': 2})
('Rimac', 'ALBEDI_SAC', {'weight': 1})
('Rimac', 'MILCORP_EIRL', {'weight': 1})
('Rimac', 'C_Y_R_SAC', {'weight': 1})
('Rimac', 'CRJ_SAC', {'weight': 1})
('Rimac', 'COMPANIA_GRA_CONSTRUCCIONES', {'weight': 1})
('San_Borja', 'CORPORACION_LINARES_SAC', {'weight': 1})
('San_Borja', 'ACO_EIRL', {'weight': 1})
('San_Borja', 'SANTO_DOMINGO_SAC', {'weight': 1})
('San_Borja', 'CROS_PERU_SAC', {'weight': 1})
('San_Borja', 'HA_CONSTRUCCION_SAC', {'weight': 1})
('San_Borja', 'HB_SAC', {'weight': 1})
('San_Borja', 'KUNAQ_SAC', {'weight': 1})
('San_Borja', 'INVERSIONES_LIBERSCO', {'weight': 1})
('San_Borja', 'PORFISA_CONTRATISTAS_GENERALES', {'weight': 1})
('San_Borja', 'GRUPO_VITESSE_SAC', {'weight': 1})
('San_Isidro', 'SIADEC_INGENIEROS_SAC', {'weight': 1})
('San_Isidro', 'PJK', {'weight': 2})
('San_Isidro', 'AGREDA_GALLARDAY&JARA_SAC', {'weight': 1})
('San_Isidro', 'CONTRUCTORA_VALDIVIESO', {'weight': 1})
('San_Isidro', 'CODENSA_SAC', {'weight': 2})
('San_Isidro', 'AJC_SAC', {'weight': 2})
('San_Isidro', 'ARCONST_SAC', {'weight': 1})
('San_Isidro', 'INGCONS_EIRL', {'weight': 2})
('San_Isidro', 'CONTINENTAL_SAC', {'weight': 1})
('San_Isidro', 'LINGH_SAC', {'weight': 2})
('San_Isidro', 'CONSTRUCCIONES_METALICAS_TAE', {'weight': 1})
('San_Isidro', 'MJE_SAC', {'weight': 1})
('San_Isidro', 'CHAVISAN_EIRL', {'weight': 1})
('San_Isidro', 'VIALUSA_SAC', {'weight': 1})
('San_Isidro', 'A&L_SAC', {'weight': 1})
('San_Isidro', 'B&C_SA', {'weight': 1})
('San_Isidro', 'FAKECC_SAC', {'weight': 1})
('San_Isidro', 'MT_PROYECTOS_Y_OBRAS_SAC', {'weight': 1})
('San_Isidro', 'RGG_SAC', {'weight': 1})
('San_Juan_de_Lurigancho', 'INGEOBRAS_SAC', {'weight': 1})
('San_Juan_de_Lurigancho', 'COPER', {'weight': 1})
('San_Juan_de_Lurigancho', 'CONINTEC_SRL', {'weight': 1})
('San_Juan_de_Lurigancho', 'G_Y_R_SAC', {'weight': 1})
('San_Juan_de_Lurigancho', 'C&M_GARCIA_CONTRATISTAS_Y_CONSULTORES_SAC', {'weight': 4})
('San_Juan_de_Lurigancho', 'ALESOF_EIRL', {'weight': 2})
('San_Juan_de_Lurigancho', 'ISS_CONSTRUCTORA_SAC', {'weight': 3})
('San_Juan_de_Lurigancho', 'OUTPUT_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'ESPINAR_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'JJP_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'COPER', {'weight': 2})
('San_Juan_de_Miraflores', 'FALCON_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'NARDDY_EIRL', {'weight': 2})
('San_Juan_de_Miraflores', 'JOMF_SRL', {'weight': 1})
('San_Juan_de_Miraflores', 'RASYR_CONSTRUCTORA', {'weight': 2})
('San_Juan_de_Miraflores', 'CONINTEC_SRL', {'weight': 1})
('San_Juan_de_Miraflores', 'Y_M_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'ROMAYSE_SAC', {'weight': 2})
('San_Juan_de_Miraflores', 'CRJ_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'NATHAN_EIRL', {'weight': 1})
('San_Juan_de_Miraflores', 'CONSTRUCTORA_VANESSA_ORIETTA', {'weight': 1})
('San_Juan_de_Miraflores', 'ICVSA_SA', {'weight': 1})
('San_Juan_de_Miraflores', '1.0...201', {'weight': 1})
('San_Juan_de_Miraflores', 'JBG_SAC', {'weight': 2})
('San_Juan_de_Miraflores', 'MYVEC_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'INVERSIONES_ALVAREZ_CONTRATISTAS_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'INVERSIONES_BALY_EIRL', {'weight': 1})
('San_Juan_de_Miraflores', 'CESPEDES_EDGAR', {'weight': 1})
('San_Juan_de_Miraflores', 'SAM_BLASS_SAC', {'weight': 1})
('San_Juan_de_Miraflores', 'CONSTRUCTORA_REVENGE_EIRL', {'weight': 1})
('San_Luis', 'JUSAL_INVERSIONES', {'weight': 1})
('San_Luis', 'JARO', {'weight': 2})
('San_Luis', 'CONSTRUCTORA_Y_SERVICIOS_C&C_SRL', {'weight': 2})
('San_Luis', 'AMERIKA_PROMASER_SRL', {'weight': 1})
('San_Luis', 'CORPORACION_E_INVERSIONES_H&A_SAC', {'weight': 2})
('San_Luis', 'INVERSIONES_Y_CONTRATISTAS_GRUPO_7_SAC', {'weight': 2})
('San_Luis', 'CAMHARO_SAC', {'weight': 1})
('San_Martin_de_Porres', 'METACONTROL_SAC', {'weight': 2})
('San_Martin_de_Porres', 'CONSTRUCTORA_DOLPHIN_SAC', {'weight': 1})
('San_Martin_de_Porres', 'JUSAL_INVERSIONES', {'weight': 1})
('San_Martin_de_Porres', 'SIADEC_INGENIEROS_SAC', {'weight': 2})
('San_Martin_de_Porres', 'LUMAYJE_SAC', {'weight': 3})
('San_Martin_de_Porres', 'ESPINAR_SAC', {'weight': 1})
('San_Martin_de_Porres', 'COSISE_CONSTRUCTORA', {'weight': 2})
('San_Martin_de_Porres', 'GESTION&CONSTRUCCION_SAC', {'weight': 1})
('San_Martin_de_Porres', 'COPER', {'weight': 1})
('San_Martin_de_Porres', 'COMAPORD_SAC', {'weight': 1})
('San_Martin_de_Porres', 'JELY_CONTRATISTAS', {'weight': 1})
('San_Martin_de_Porres', 'OSERGEN_SAC', {'weight': 1})
('San_Martin_de_Porres', 'CONSTRUCTORA_TANOS', {'weight': 1})
('San_Martin_de_Porres', 'JOMF_SRL', {'weight': 1})
('San_Martin_de_Porres', 'C&C_SRL', {'weight': 1})
('San_Martin_de_Porres', 'VCP_CONSULTORES_Y_EJECUTORES', {'weight': 2})
('San_Martin_de_Porres', 'EROVA_SAC', {'weight': 2})
('San_Martin_de_Porres', 'JOVE_WILLIAM', {'weight': 1})
('San_Martin_de_Porres', 'JOVE&JOVE_SAC', {'weight': 1})
('San_Martin_de_Porres', 'CONTRATISTAS_YOUNG_SAC', {'weight': 1})
('San_Martin_de_Porres', 'Y_M_SAC', {'weight': 1})
('San_Martin_de_Porres', 'ASFALTOS_Y_PAVIMENTOS_SAC', {'weight': 1})
('San_Martin_de_Porres', 'MT_PROYECTOS_Y_OBRAS_SAC', {'weight': 1})
('San_Martin_de_Porres', 'MYVEC_SAC', {'weight': 1})
('San_Martin_de_Porres', 'C&M_GARCIA_CONTRATISTAS_Y_CONSULTORES_SAC', {'weight': 1})
('San_Martin_de_Porres', 'ALESOF_EIRL', {'weight': 1})
('San_Martin_de_Porres', 'CAMHARO_SAC', {'weight': 1})
('San_Martin_de_Porres', 'SERBEMUZ_INDUSTRIALES&SERVICIOS_SAC', {'weight': 1})
('San_Martin_de_Porres', 'CJV_CONTRATISTAS_GENERALES', {'weight': 1})
('San_Martin_de_Porres', 'JJVL_CONTRATISTAS_GENERALES', {'weight': 1})
('San_Martin_de_Porres', 'ALTAVISTA_INVERSIONES_GLOBALES_SAC', {'weight': 1})
('San_Martin_de_Porres', 'DAHE_SERVICIOS_GENERALES', {'weight': 1})
('San_Martin_de_Porres', 'CONSULTORES_Y_CONSTRUCTORA_MARKA_JIRKA', {'weight': 2})
('San_Martin_de_Porres', 'CONSTRUCCIONES_&_CONSULTORES_ABIGATI', {'weight': 2})
('San_Martin_de_Porres', 'FM_CONTRATISTAS_GENERALES', {'weight': 1})
('San_Martin_de_Porres', 'LFX_SAC', {'weight': 1})
('San_Miguel', 'GMP_SAC', {'weight': 1})
('San_Miguel', 'CCODEINGESA', {'weight': 1})
('San_Miguel', 'CONSTRUCTORA_HERRERA_PERU_EIRL', {'weight': 1})
('San_Miguel', 'CONSTRUCTORA_MJR_SA', {'weight': 1})
('San_Miguel', 'CARBOZ_C_Y_M_EIRL', {'weight': 1})
('Santa_Anita', 'HUAYCHAOLA_SAC', {'weight': 1})
('Santa_Anita', 'M&S_PROYECTS', {'weight': 1})
('Santa_Anita', 'MEJESA_SRL', {'weight': 1})
('Santa_Anita', 'ACO_EIRL', {'weight': 1})
('Santa_Anita', 'G_Y_L_MAGISTER_SALVADOR', {'weight': 1})
('Santa_Anita', 'PACORQ_SRL', {'weight': 1})
('Santa_Anita', 'RENCCO_CONTRATISTAS_GENERALES_SAC', {'weight': 1})
('Santa_Anita', 'ABBANCE_COMPANY_SAC', {'weight': 1})
('Santa_Anita', 'CONSTRUCCIONES_COMAFE_SAC', {'weight': 2})
('Santa_Anita', 'CONSTRUCT_MABSA_INGEN_CONTRAT_GRALES', {'weight': 2})
('Santa_Anita', 'CONSTRUCTORA_ANAID', {'weight': 1})
('Santa_Anita', 'WALLALLO_CONSTRUCCION_E_INGENIERIA', {'weight': 1})
('Santa_Anita', 'GMC_PROYECTOS_Y_CONSTRUCCIONES', {'weight': 1})
('Santa_Anita', 'CONSTRUCTORA&CONTRATISTAS_GENERALES_SUSAN', {'weight': 1})
('Santa_Maria_del_Mar', 'HIGH_CONSTRUCTIONS', {'weight': 1})
('Santa_Rosa', 'CONSORCIO_MONTENEGRO', {'weight': 1})
('Santa_Rosa', 'AGREDA_GALLARDAY&JARA_SAC', {'weight': 1})
('Santa_Rosa', 'ALE_INGENIERIA&CONSTRUCCION', {'weight': 1})
('Santa_Rosa', 'CORPORACION_JARA_Y_CHAVEZ', {'weight': 1})
('Santa_Rosa', 'SERBEMUZ_INDUSTRIALES&SERVICIOS_SAC', {'weight': 1})
('Santa_Rosa', 'AC&V_INGENIEROS_CONTRATISTAS', {'weight': 1})
('Santa_Rosa', 'PRIMIAN_INVERSIONES', {'weight': 1})
('Santa_Rosa', 'CORPORACION_FRANMEGA', {'weight': 1})
('Santiago_de_Surco', 'HUAYCHAOLA_SAC', {'weight': 1})
('Santiago_de_Surco', 'CONSTRUCTORA_DOLPHIN_SAC', {'weight': 1})
('Santiago_de_Surco', 'SIADEC_INGENIEROS_SAC', {'weight': 1})
('Santiago_de_Surco', 'Y_M_SAC', {'weight': 1})
('Santiago_de_Surco', 'HIGH_CONSTRUCTIONS', {'weight': 2})
('Santiago_de_Surco', 'ACO_EIRL', {'weight': 1})
('Santiago_de_Surco', 'SANTO_DOMINGO_SAC', {'weight': 1})
('Santiago_de_Surco', 'V_Y_P_CONSTRUCTORA_Y_SERVICIOS_GENERALES_SAC', {'weight': 1})
('Santiago_de_Surco', 'E&G_CONTRATISTAS_GENERALES_SRL', {'weight': 1})
('Santiago_de_Surco', 'PROYECTOS_INDUSTRIALES_JR_SAC', {'weight': 1})
('Surquillo', 'METACONTROL_SAC', {'weight': 2})
('Surquillo', 'ISS_CONSTRUCTORA_SAC', {'weight': 1})
('Surquillo', 'ROHA_CONSTRUCTORES&CONSULTORES', {'weight': 1})
('Villa_El_Salvador', 'INVERSIONES_LUMI_EIRL', {'weight': 1})
('Villa_El_Salvador', 'CONSTRUCTORA_MTT_EIRL', {'weight': 1})
('Villa_El_Salvador', 'CONSTRUCTORA_GUTIERREZ&ASOCIADOS', {'weight': 1})
('Villa_Maria_del_Triunfo', 'LEON_CONTRATISTAS', {'weight': 1})
('Villa_Maria_del_Triunfo', 'CONSTRUCTORA_MTL_EIRL', {'weight': 2})
('Paramonga', 'CONSTRUCTORA_MVM_INGENIEROS', {'weight': 1})
('Paramonga', 'COMUNE_CONSTRUCTORA_SAC', {'weight': 1})
('Pativilca', 'PEDRO_PABLO_MARTINEZ_INFANTES_EIRL', {'weight': 1})
('Pativilca', 'C&A_MACONI_INGENIEROS_EIRL', {'weight': 1})
('Pativilca', 'EMPRESA_J&F_EIRL', {'weight': 3})
('Pativilca', 'ESTANCIA_CASA_BLANCA_EIRL', {'weight': 1})
('Pativilca', 'TOBE_SRL', {'weight': 2})
('Pativilca', 'COFAB_EIRL', {'weight': 1})
('Supe', 'ARQCON_CONSULTORES_Y_EJECUTORES', {'weight': 1})
('Supe', 'GRUPO_MONTALVO_PRADA_SAC', {'weight': 2})
('Supe', 'INGENIERIA_EN_CONSTRUCCION_SOLIS', {'weight': 1})
('Supe', 'NEGOCIOS_M_Y_G_SERVICIOS_GENERALES', {'weight': 1})
('Supe', 'CORPORACION_EL_ASPERO', {'weight': 1})
('Cajatambo', 'M&S_PROYECTS', {'weight': 1})
('Cajatambo', 'JF_CONSTRUCTORES_SAC', {'weight': 1})
('Arahuay', 'CORPORACION_HZ_CONTRATISTAS_GENERALES', {'weight': 1})
('Arahuay', 'INVERSIONES_HERMANOS_CADILLO_MOTA', {'weight': 1})
('Santa_Rosa_de_Quives', 'GEL_SAC', {'weight': 1})
('Santa_Rosa_de_Quives', 'JL_SAC', {'weight': 1})
('Santa_Rosa_de_Quives', 'AQUIÑO_SRL', {'weight': 1})
('Santa_Rosa_de_Quives', 'V_Y_R_CONSTRUCTORA_SANCHEZ_SRL', {'weight': 1})
('San_Vicente_de_Cañete', 'ESPINAR_SAC', {'weight': 1})
('San_Vicente_de_Cañete', 'CONTINENTAL_SAC', {'weight': 1})
('San_Vicente_de_Cañete', 'INVERSIONES_A_Y_C_SAC', {'weight': 1})
('San_Vicente_de_Cañete', 'CONTALMA_SRL', {'weight': 2})
('San_Vicente_de_Cañete', 'MURCIA_EIRL', {'weight': 1})
('San_Vicente_de_Cañete', 'ZAVALA_GROUP_SAC', {'weight': 1})
('San_Vicente_de_Cañete', 'SERVICIOS_FERRETEROS_ALBERT', {'weight': 1})
('San_Vicente_de_Cañete', 'PROMATEC_INGENIERIA&CONSTRUCCION', {'weight': 2})
('San_Vicente_de_Cañete', 'CONSTRUCTORA_CWCM', {'weight': 1})
('San_Vicente_de_Cañete', 'CJ&L_ATO_RENDIMIENTO_EN_CONSULTORIA_Y_EJECUTORIA_DE_INFRAESTRUCTURAS', {'weight': 1})
('San_Vicente_de_Cañete', 'VM_ING_SAC', {'weight': 1})
('San_Vicente_de_Cañete', 'G&I_ASOCIADOS_CONSULTORES', {'weight': 1})
('San_Vicente_de_Cañete', 'CONSTRUCTORA_SEVMI_INVERSIONES', {'weight': 1})
('San_Vicente_de_Cañete', 'CONSUR_CONSTRUCTORA_Y_CONSULTORIA', {'weight': 1})
('San_Vicente_de_Cañete', 'KETU_SERVICIOS_Y_REPRESENTACIONES', {'weight': 2})
('San_Vicente_de_Cañete', 'SALAZAR_Y_GALLO_CONTRATISTAS', {'weight': 1})
('San_Vicente_de_Cañete', 'R_C_R_CONTRATISTAS_GENERALES', {'weight': 1})
('San_Vicente_de_Cañete', 'JG_INGENIERIA_SERVICIOS_Y_PROYECTOS', {'weight': 1})
('San_Vicente_de_Cañete', 'ENGINEER_ASSOCIATION_SAC', {'weight': 1})
('San_Vicente_de_Cañete', 'DERC_CONSULTORES_Y_EJECUTORES', {'weight': 1})
('Asia', 'ESPINAR_SAC', {'weight': 2})
('Asia', 'ZAVALA_GROUP_SAC', {'weight': 1})
('Asia', 'SERVICIOS_FERRETEROS_ALBERT', {'weight': 1})
('Asia', 'CJ&L_ATO_RENDIMIENTO_EN_CONSULTORIA_Y_EJECUTORIA_DE_INFRAESTRUCTURAS', {'weight': 2})
('Asia', 'SALAZAR_Y_GALLO_CONTRATISTAS', {'weight': 1})
('Asia', 'JG_INGENIERIA_SERVICIOS_Y_PROYECTOS', {'weight': 1})
('Asia', 'CGG_MULTISERNING_GENERALES', {'weight': 2})
('Asia', 'ISF_EIRLS', {'weight': 1})
('Asia', 'GRUPO_FRANCO_SAC', {'weight': 1})
('Asia', 'ROJU_EIRL', {'weight': 1})
('Asia', 'ALUBE_EIRL', {'weight': 1})
('Asia', 'TOKYO_SAC', {'weight': 1})
('Cerro_Azul', 'COSISE_CONSTRUCTORA', {'weight': 1})
('Cerro_Azul', 'CGG_MULTISERNING_GENERALES', {'weight': 1})
('Cerro_Azul', 'INGENIERIA&CONSULTORIA_EIRL', {'weight': 1})
('Cerro_Azul', 'FRAGON_SAC', {'weight': 1})
('Cerro_Azul', 'CS_SAC', {'weight': 1})
('Chilca', 'DAMBEZ_COMPANY', {'weight': 1})
('Chilca', 'CONSTRUCTORA_ALFA&BETA', {'weight': 1})
('Chilca', 'CORPORACION_ALHE_CONTRATISTAS_GENERALES', {'weight': 1})
('Chilca', 'CONSTRUCTORA_GALU', {'weight': 1})
('Chilca', 'INVERSIONES_MARVELZ', {'weight': 1})
('Chilca', 'ORIENCE_PERU_SAC', {'weight': 1})
('Chilca', '1.0...288', {'weight': 1})
('Chilca', 'INVERSIONES_Y_CONSTRUCCIONES_RUVIAT', {'weight': 1})
('Imperial', 'AP_CONTRATISTAS_GENERALES_SAC', {'weight': 1})
('Imperial', 'J_Y_S_SERVICIOS_GENERALES_SAC', {'weight': 1})
('Imperial', 'INVERSIONES_EJECUTORES_Y_CONSULTORES_DACA', {'weight': 1})
('Imperial', 'EMPRESA_MAQUISA_SAC', {'weight': 1})
('Imperial', 'CGG_MULTISERNING_GENERALES', {'weight': 1})
('Imperial', 'PORTICCONS_SAC', {'weight': 1})
('Imperial', 'JK_CONSULTORES_Y_CONSTRUCTORES', {'weight': 1})
('Imperial', 'TEGAM_SAC', {'weight': 1})
('Imperial', 'CONSTRUCCIONES_LORENA', {'weight': 1})
('Imperial', 'GRUPO_H_Y_S', {'weight': 1})
('Mala', 'CORPORACION_LINARES_SAC', {'weight': 1})
('Mala', 'VM_ING_SAC', {'weight': 2})
('Mala', 'FRAGON_SAC', {'weight': 1})
('Mala', 'ROKA_SAC', {'weight': 2})
('Mala', 'MIDORI_SUR_SAC', {'weight': 2})
('Mala', 'CONSTRUCTORA_Y_CONSULTORIAS_ARIAN_SAC', {'weight': 1})
('Mala', 'PROYECTOS_CABA_ASOCIADOS_SAC', {'weight': 1})
('Mala', 'PILLCO201_EIRL', {'weight': 1})
('Mala', 'PILAR_DE_LA_CRUZ_SAC', {'weight': 1})
('Mala', 'ALCO_CONSULTORES_Y_CONSTRUCTORES_GENERALES_SAC', {'weight': 1})
('Mala', 'INGENIERIA_APLICADA_EN_SUPERVISION_SAC', {'weight': 1})
('Mala', 'CONSTRUCTORA_CHOCOS_ESPINOZA_SRL', {'weight': 1})
('Mala', 'PS&C_DE_VANGUARDIA_EIRL', {'weight': 1})
('Mala', 'CONSORCIO_B&V_INGENIEROS_EMPRESA_INDIVIDUAL', {'weight': 1})
('Mala', 'EL_ZETA_SAC', {'weight': 1})
('Quilmana', 'COSISE_CONSTRUCTORA', {'weight': 1})
('Quilmana', 'EMPRESA_MAQUISA_SAC', {'weight': 2})
('Quilmana', 'TOKYO_SAC', {'weight': 1})
('Quilmana', 'CS_SAC', {'weight': 1})
('Quilmana', 'CONSULTORIA&INGENIERIA_PERUANA_SAC', {'weight': 2})
('Quilmana', 'KALEPH_SAC', {'weight': 2})
('Quilmana', 'LAURA_SAMANIEGO_SAC', {'weight': 1})
('Quilmana', 'E&F_SAC', {'weight': 1})
('Santa_Cruz_de_Flores', 'KALEPH_SAC', {'weight': 1})
('Santa_Cruz_de_Flores', 'LAURA_SAMANIEGO_SAC', {'weight': 1})
('Santa_Cruz_de_Flores', 'CORPORACION_INGENIERIA&CONSULTORIA_EIRL', {'weight': 1})
('Huaral', 'LUCEMAR_EIRL', {'weight': 1})
('Huaral', 'CORPORACION_LINARES_SAC', {'weight': 1})
('Huaral', 'OVLV_SAC', {'weight': 1})
('Huaral', 'CONTINENTAL_SAC', {'weight': 1})
('Huaral', 'INVERSIONES_Y_CONTRATISTAS_GRUPO_7_SAC', {'weight': 1})
('Huaral', 'CORPORACION_ALHE_CONTRATISTAS_GENERALES', {'weight': 1})
('Huaral', 'GREEN_GOLD_SAC', {'weight': 1})
('Huaral', 'OBREGON_CONTRATISTAS_GENERALES_SAC', {'weight': 1})
('Huaral', 'TECNOMIN_DATA', {'weight': 1})
('Aucallama', 'PEDRO_PABLO_MARTINEZ_INFANTES_EIRL', {'weight': 2})
('Aucallama', 'KAJIRI_EIRL', {'weight': 1})
('Aucallama', 'ALPAMAYO_SAC', {'weight': 1})
('Aucallama', 'A&V_EIRL', {'weight': 1})
('Aucallama', 'BONIFACIO_SAC', {'weight': 1})
('Aucallama', 'PAMED_EIRL', {'weight': 1})
('Chancay', 'LUCEMAR_EIRL', {'weight': 1})
('Chancay', 'CORPORACION_LINARES_SAC', {'weight': 1})
('Chancay', 'OVLV_SAC', {'weight': 1})
('Chancay', 'CONTINENTAL_SAC', {'weight': 1})
('Chancay', 'INVERSIONES_Y_CONTRATISTAS_GRUPO_7_SAC', {'weight': 1})
('Chancay', 'CORPORACION_ALHE_CONTRATISTAS_GENERALES', {'weight': 1})
('Chancay', 'GREEN_GOLD_SAC', {'weight': 1})
('Chancay', 'OBREGON_CONTRATISTAS_GENERALES_SAC', {'weight': 1})
('Chancay', 'TECNOMIN_DATA', {'weight': 1})
('Ihuari', 'GEOX_EIRL', {'weight': 1})
('Ihuari', 'FOREX_CONSTRUCTIONS_EIRL', {'weight': 1})
('Santa_Cruz_de_Andamarca', 'DAMBEZ_COMPANY', {'weight': 1})
('Santa_Cruz_de_Andamarca', 'AI&CB_SRL', {'weight': 1})
('Santa_Cruz_de_Andamarca', 'MARGIL_SAC', {'weight': 1})
('Santa_Cruz_de_Andamarca', 'ICAT_SAC', {'weight': 1})
('Antioquia', 'AZUR_SRL', {'weight': 1})
('Antioquia', 'S&T_SRL', {'weight': 1})
('Chicla', 'M_Y_W_VERTIZ_CARLOS_SAC', {'weight': 1})
('Chicla', 'EJECUTORES_Y_CONSULTRES_WVC_SAC', {'weight': 1})
('Huachupampa', 'ABBANCE_COMPANY_SAC', {'weight': 2})
('Huachupampa', 'CORPORACION_GRUPO_SOBRADO_SAC', {'weight': 1})
('Huachupampa', 'FERREMAR_PEREZ_SAC', {'weight': 1})
('Huanza', 'REBOLLAR_SRL', {'weight': 1})
('Huanza', 'CODEING_SAC', {'weight': 1})
('Huarochiri', 'JL_BARRIENTOS_SAC', {'weight': 1})
('Ricardo_Palma', 'MICLEBY_SAC', {'weight': 1})
('San_Antonio', 'JAGIXA', {'weight': 1})
('San_Antonio', 'LUCEMAR_EIRL', {'weight': 1})
('San_Antonio', 'VM_ING_SAC', {'weight': 1})
('San_Antonio', 'FRAGON_SAC', {'weight': 3})
('San_Antonio', 'D&P_SAC', {'weight': 3})
('San_Antonio', 'ROMAC_EIRL', {'weight': 1})
('San_Antonio', 'ROKA_SAC', {'weight': 1})
('San_Antonio', 'INGECOL', {'weight': 1})
('San_Antonio', 'JFT_EIRL', {'weight': 1})
('San_Antonio', 'ADECON', {'weight': 1})
('San_Antonio', 'GHALIA_EIRL', {'weight': 1})
('San_Antonio', 'ARYSA_SAC', {'weight': 1})
('Santiago_de_Anchucaya', 'INVERSIONES_HERMANOS_CADILLO_MOTA', {'weight': 2})
('Santiago_de_Anchucaya', 'ARMAS_RODRIGUEZ_VICTOR', {'weight': 2})
('Santo_Domingo_de_los_Olleros', 'CONSTRUCTORA_NEINCO_SAC', {'weight': 1})
('Santo_Domingo_de_los_Olleros', 'CORPORACION_JESSKARSA_SAC', {'weight': 1})
('Santo_Domingo_de_los_Olleros', 'CONSTRUCCIONES_E_INVERSIONES_KWT_SAC', {'weight': 1})
('Santo_Domingo_de_los_Olleros', 'S&H_CONSTRUCTORA_SULQUITA_HUAMANI_SRL', {'weight': 1})
('Surco(Huarochiri)', 'JL_BARRIENTOS_SAC', {'weight': 1})
('Huacho', 'INGEOBRAS_SAC', {'weight': 1})
('Huacho', 'VACHAVEZ_SRL', {'weight': 1})
('Huacho', 'VCP_CONSULTORES_Y_EJECUTORES', {'weight': 3})
('Huacho', 'MONTALVO_CONSTRUCTORA', {'weight': 1})
('Huacho', 'CORPORACION_E_INVERSIONES_H&A_SAC', {'weight': 1})
('Huacho', 'INVERSIONES_Y_CONTRATISTAS_GRUPO_7_SAC', {'weight': 1})
('Huacho', 'PEDRO_PABLO_MARTINEZ_INFANTES_EIRL', {'weight': 1})
('Huacho', 'EMPRESA_J&F_EIRL', {'weight': 2})
('Huacho', 'SERVIPROYECTOS_ALYMAR_SAC', {'weight': 1})
('Huacho', 'EMPRESA_CONSTRUCTORA_LOPEZ_SAC', {'weight': 1})
('Huacho', 'CONTRATISTAS_GENERALES_HUAURA_SRL', {'weight': 1})
('Huacho', 'COJAPRI_INGENIEROS_EIRL', {'weight': 1})
('Huacho', 'COINBISE_SAC', {'weight': 1})
('Huacho', 'CONZEL_SAC', {'weight': 1})
('Huacho', 'CORPORACION_ANDINA_YIRET_EIRL', {'weight': 1})
('Huacho', 'SAN_AGUSTIN_EIRL_CONTRATISTAS_GENERALES', {'weight': 1})
('Huacho', 'CORPORACION_DAGOBA_SAC', {'weight': 2})
('Huacho', "CONSTRUCTORA_Y_CORPORACION_D'GALLO_EIRL", {'weight': 1})
('Huacho', 'AMPER_SISTEMAS_SUCURSAL_PERU_SA', {'weight': 1})
('Huacho', 'ARES_SERVICIOS_GLOBALES_SAC', {'weight': 1})
('Huacho', 'CONSAJAK_CIX_SAC', {'weight': 1})
('Huacho', 'FEMACH_SAC', {'weight': 1})
('Huacho', 'EIFEL_CONSTRUCCIONES_Y_SERVICIOS_GENERALES_SAC', {'weight': 1})
('Huacho', 'DAIDARIUS_SAC', {'weight': 1})
('Huacho', 'INVERSIONES_MINERAS_TOROMIN_SAC', {'weight': 1})
('Huacho', 'CONSAGA_INGENIEROS_CONTRATISTAS_GENERALES_SRL', {'weight': 1})
('Huacho', 'TELEANDES_CONTRATISTAS_GENERALES_SAC', {'weight': 1})
('Huacho', 'TEINGECON_SAC', {'weight': 1})
('Huacho', 'GRUPO_HTS_SAC', {'weight': 1})
('Huacho', 'CORPORATION_TEKNY&RAN_EIRL', {'weight': 1})
('Huacho', 'CONSTRUCTORA_INMOBILIARIA_GOLD_SAC', {'weight': 1})
('Huacho', 'CONSTRUCTORA_GERED_SAC', {'weight': 1})
('Huacho', 'PSD_FORTALEZA_SAC', {'weight': 1})
('Huaura', 'SIMON_HUERTA_ROJAS_SAC', {'weight': 1})
('Huaura', 'HEMSA_SRL', {'weight': 1})
('Huaura', 'AOC_SRL', {'weight': 1})
('Sayan', 'CONSTRUCTORA_Y_SERVICIOS_GENERALES_A&R_SRL', {'weight': 1})
('Sayan', 'GRUPO_CONSTRUCTOR_HAZ_Y_HNOS_LA_SRL', {'weight': 1})
('Sayan', 'SERVICIOS_Y_CONSTRUCCION_VILLAVICENCIO_SAC', {'weight': 1})
('Sayan', 'COPCOGE_EIRL', {'weight': 2})
('Sayan', 'NYM_ARELLANO_CONSTRUCTOR_SAC', {'weight': 1})
('Vegueta', 'DAMBEZ_COMPANY', {'weight': 2})
('Vegueta', 'ALPAMAYO_SAC', {'weight': 1})
('Vegueta', 'AOC_SRL', {'weight': 1})
('Vegueta', 'FASA_SAC', {'weight': 1})
('Vegueta', 'AGRIBUSINESS_SAC', {'weight': 1})
('Vegueta', 'CIVIC_EIRL', {'weight': 1})
('Vegueta', 'GOE_EIRL', {'weight': 1})
('Vegueta', 'PERUINSA_SAC', {'weight': 1})
('Vegueta', 'CONSTRUCTORA_Y_CONSULTORA_DEL_PERU_SAC', {'weight': 1})
('Hongos', 'G&I_ASOCIADOS_CONSULTORES', {'weight': 1})
('Hongos', 'ZIBA_SAC', {'weight': 1})
('Omas', 'DEREK_CONTRATISTAS_GENERALES_SAC', {'weight': 1})
('Omas', 'GRUPO_ST_INGENIERIA&CONSTRUCCION_EIRL', {'weight': 1})
('Quinches', 'INVERSIONES_HERMANOS_CADILLO_MOTA', {'weight': 1})
('Quinches', 'ARMAS_RODRIGUEZ_VICTOR', {'weight': 1})
('Tauripampa', 'C_Y_C_SAC', {'weight': 1})
('Tauripampa', 'HUMMINGTRIP_SAC', {'weight': 1})
('Tauripampa', 'GC_SAC', {'weight': 1})
('Tauripampa', 'P&J_EIRL', {'weight': 1})
('Tupe', 'LOA_WAUKIS_SAC', {'weight': 2})
('Tupe', 'CODECA_SAC', {'weight': 1})
('Bellavista', 'M&S_PROYECTS', {'weight': 1})
('Bellavista', 'HUASCARAN_SAC', {'weight': 2})
('Bellavista', 'CVJ_CONTRATISTAS_GENERALES_SRL', {'weight': 1})
('Bellavista', 'GELI_SAC', {'weight': 1})
('Bellavista', "LOREN'S_SAC", {'weight': 1})
('La_Perla', 'SIADEC_INGENIEROS_SAC', {'weight': 2})
('La_Perla', 'NEBCAS_SAC', {'weight': 1})
('La_Perla', 'CODENSA_SAC', {'weight': 1})
('La_Perla', 'XIANY_SAC', {'weight': 1})
('La_Punta', 'ARCONST_SAC', {'weight': 1})
('La_Punta', 'GRUPO_VITESSE_SAC', {'weight': 1})
('La_Punta', 'MILENIUM_SAC', {'weight': 3})
('La_Punta', 'ORDESA_A&C_SAC', {'weight': 2})
('La_Punta', 'QUEVEDO_JIMENEZ_CESAR_AUGUSTO', {'weight': 1})
('La_Punta', 'LUSA_SRL', {'weight': 1})
('Ventanilla', 'ZRINCON_EIRL', {'weight': 3})
('Ventanilla', 'MIROVAL_SAC', {'weight': 1})
('Ventanilla', 'C&C_SRL', {'weight': 1})
('Ventanilla', 'CONTRUCTORA_VALDIVIESO', {'weight': 1})
('Ventanilla', 'M&S_PROYECTS', {'weight': 1})
('Ventanilla', 'ARCONST_SAC', {'weight': 2})
('Ventanilla', 'EDIRESA_SAC', {'weight': 3})
('Ventanilla', 'JF_CONSTRUCTORES_SAC', {'weight': 1})
('Ventanilla', 'ORDESA_A&C_SAC', {'weight': 1})
('Ventanilla', 'SAUCEDO_INGENIERIA_Y_CONSTRUCCION_SAC', {'weight': 3})
('Ventanilla', 'NFRC_EIRL', {'weight': 1})
('Ventanilla', 'REBECSA_SAC', {'weight': 4})
('Ventanilla', 'BECERRA_Y_BECERRA_CONSTRUCTORES_SAC', {'weight': 2})
('Ventanilla', 'SAENZ_CONSTRUCCTION_EMPRESA', {'weight': 2})
('Ventanilla', 'GRUPO_REMEC_SAC', {'weight': 2})
('Ventanilla', 'DICIESA_EIRL', {'weight': 3})
('Ventanilla', 'CONSTRUCTORA_NISSI_SAC', {'weight': 3})
('Ventanilla', 'SAMIR_CONTRATISTAS_GENERALES_SAC', {'weight': 2})
('Ventanilla', 'NEW_ACROPOLIS_SAC', {'weight': 1})
('Ventanilla', 'INVERSIONES_CAVIANDINA_SAC', {'weight': 2})
('Ventanilla', 'DAZER_CONSTRUCTION_SAC', {'weight': 2})
('Ventanilla', 'GRALAZ_SAC', {'weight': 1})
('Ventanilla', 'ECOTRAM_EIRL', {'weight': 1})
('Ventanilla', 'CORPORACION_INGENIERIA_Y_DESARROLLO_SAC', {'weight': 3})
('Ventanilla', 'W&W_CONSTRUCTORES_SAC', {'weight': 1})
('Ventanilla', 'GEOTEGG_SAC', {'weight': 1})
('Ventanilla', 'MAKI_ASOCIADOS_SAC', {'weight': 1})
('Ventanilla', 'COINVEFER_EIRL', {'weight': 1})
('Ventanilla', 'G&P_EL_ROBLE_SAC', {'weight': 1})
('Mi_Peru', 'COPER', {'weight': 2})
('Mi_Peru', 'JARO', {'weight': 1})
('Mi_Peru', 'MALLQUI_SAC', {'weight': 1})
('Mi_Peru', 'CROS_PERU_SAC', {'weight': 2})
('Mi_Peru', 'HB_SAC', {'weight': 1})
('Mi_Peru', 'CAMHARO_SAC', {'weight': 1})
('Mi_Peru', 'ARIS_SAC', {'weight': 1})
('Mi_Peru', 'JE_EIRL', {'weight': 1})
('Mi_Peru', 'CRANT_SAC', {'weight': 1})

3.1. Visualizamos la red¶

In [41]:
import matplotlib.pyplot as plt

pos = nx.bipartite_layout(victoria, nodes=municipalidades)  

plt.figure(figsize=(15, 10))
nx.draw_networkx_nodes(victoria, pos, nodelist=municipalidades, node_color="lightblue", node_size=1500)
nx.draw_networkx_nodes(victoria, pos, nodelist=empresas, node_color="lightgreen", node_size=1500)
nx.draw_networkx_edges(victoria, pos, width=1.5)

nx.draw_networkx_labels(victoria, pos, font_size=5, font_weight="bold")

plt.title("Red Bipartita de Contratos entre Municipalidades y Empresas")
plt.axis('off')  
plt.show()
No description has been provided for this image

Ups... Intentemos de otra forma¶

In [44]:
import matplotlib.pyplot as plt

pos = nx.spring_layout(victoria, seed=42)  

plt.figure(figsize=(10, 7))
nx.draw_networkx_nodes(victoria, pos, nodelist=municipalidades, node_color="lightblue", node_size=1500, label="Municipalidades")
nx.draw_networkx_nodes(victoria, pos, nodelist=empresas, node_color="lightgreen", node_size=1500, label="Empresas")
nx.draw_networkx_edges(victoria, pos, width=1.5)

nx.draw_networkx_labels(victoria, pos, font_size=10, font_weight="bold")

plt.legend(["Municipalidades", "Empresas"])
plt.title("Red Bipartita de Contratos entre Municipalidades y Empresas")
plt.show()
No description has been provided for this image

Probemos otra forma...¶

In [50]:
import networkx as nx
import matplotlib.pyplot as plt

plt.figure(figsize=(20, 15))

pos = nx.spring_layout(victoria, k=0.3, iterations=20)

nx.draw_networkx_nodes(victoria, pos, nodelist=municipalidades, node_color="lightblue", node_size=500)

nx.draw_networkx_nodes(victoria, pos, nodelist=empresas, node_color="lightgreen", node_size=500)

nx.draw_networkx_edges(victoria, pos, width=1.0, alpha=0.6)

nx.draw_networkx_labels(victoria, pos, font_size=7, font_weight="bold")

plt.title("Red Bipartita de Contratos entre Municipalidades y Empresas", fontsize=15)
plt.axis('off')  

plt.show()
No description has been provided for this image

Mejoramos la visualización¶

In [112]:
from pyvis.network import Network
import networkx as nx

net = Network(height="750px", width="100%", notebook=True)

for municipio in municipalidades: 
    net.add_node(str(municipio), label=str(municipio), color='lightblue', size=20)

for empresa in empresas:  
    net.add_node(str(empresa), label=str(empresa), color='lightgreen', size=20)

for u, v in victoria.edges():
    if str(u) not in net.get_nodes():
        net.add_node(str(u), label=str(u), color='lightblue' if u in municipalidades else 'lightgreen', size=20)
    if str(v) not in net.get_nodes():
        net.add_node(str(v), label=str(v), color='lightblue' if v in municipalidades else 'lightgreen', size=20)
    
    net.add_edge(str(u), str(v))

net.repulsion(node_distance=300, spring_length=150)

net.show("red_bipartita_interactiva.html")
Warning: When  cdn_resources is 'local' jupyter notebook has issues displaying graphics on chrome/safari. Use cdn_resources='in_line' or cdn_resources='remote' if you have issues viewing graphics in a notebook.
red_bipartita_interactiva.html
Out[112]:

3.2. Agrupamiento por peso¶

En este caso comprendemos el peso en torno al número de contratos que ha ganado una empresa en un determinado distrito

Contratos iguales o mayores a 2¶

In [62]:
import matplotlib.pyplot as plt
import networkx as nx

min_contratos = 2
victoria_filtered = nx.Graph()

for distrito in lima_distritos.index:
    for empresa in lima_distritos.columns:
        if lima_distritos.loc[distrito, empresa] >= min_contratos:
            victoria_filtered.add_edge(distrito, empresa, weight=lima_distritos.loc[distrito, empresa])

pos = nx.spring_layout(victoria_filtered, k=0.3, iterations=20)

municipalidades = [n for n in victoria_filtered.nodes() if n in lima_distritos.index]
empresas = [n for n in victoria_filtered.nodes() if n not in lima_distritos.index]

color_map = ["lightblue" if node in municipalidades else "lightgreen" for node in victoria_filtered.nodes()]

node_sizes = []
for node in victoria_filtered.nodes():
    if node in municipalidades:
        total_contratos = sum([victoria_filtered[u][v]['weight'] for u, v in victoria_filtered.edges(node)])
    else:
        total_contratos = sum([victoria_filtered[u][v]['weight'] for u, v in victoria_filtered.edges(node)])
    node_sizes.append(total_contratos * 200) 

plt.figure(figsize=(15, 10))
nx.draw_networkx_nodes(victoria_filtered, pos, node_color=color_map, node_size=node_sizes, alpha=0.8)
nx.draw_networkx_edges(victoria_filtered, pos, width=1.5, alpha=0.5, edge_color="grey")

nx.draw_networkx_labels(victoria_filtered, pos, font_size=8, font_weight="bold")

edge_labels = nx.get_edge_attributes(victoria_filtered, 'weight')
nx.draw_networkx_edge_labels(victoria_filtered, pos, edge_labels=edge_labels, font_size=7)

plt.title("Red Bipartita Filtrada (Contratos ≥ 2)", fontsize=15)
plt.axis('off')  
plt.show()
No description has been provided for this image

Contratos iguales o mayores a 3¶

In [65]:
import matplotlib.pyplot as plt
import networkx as nx

min_contratos_3 = 3
victoria_filtered_3 = nx.Graph()

for distrito in lima_distritos.index:
    for empresa in lima_distritos.columns:
        if lima_distritos.loc[distrito, empresa] >= min_contratos_3:
            victoria_filtered_3.add_edge(distrito, empresa, weight=lima_distritos.loc[distrito, empresa])

pos = nx.spring_layout(victoria_filtered_3, k=0.3, iterations=20)

municipalidades = [n for n in victoria_filtered_3.nodes() if n in lima_distritos.index]
empresas = [n for n in victoria_filtered_3.nodes() if n not in lima_distritos.index]

color_map = ["lightblue" if node in municipalidades else "lightgreen" for node in victoria_filtered_3.nodes()]

node_sizes = []
for node in victoria_filtered_3.nodes():
    if node in municipalidades:
        total_contratos = sum([victoria_filtered_3[u][v]['weight'] for u, v in victoria_filtered_3.edges(node)])
    else:
        total_contratos = sum([victoria_filtered_3[u][v]['weight'] for u, v in victoria_filtered_3.edges(node)])
    node_sizes.append(total_contratos * 200) 

plt.figure(figsize=(15, 10))
nx.draw_networkx_nodes(victoria_filtered_3, pos, node_color=color_map, node_size=node_sizes, alpha=0.8)
nx.draw_networkx_edges(victoria_filtered_3, pos, width=1.5, alpha=0.5, edge_color="grey")

nx.draw_networkx_labels(victoria_filtered_3, pos, font_size=8, font_weight="bold")

edge_labels = nx.get_edge_attributes(victoria_filtered_3, 'weight')
nx.draw_networkx_edge_labels(victoria_filtered_3, pos, edge_labels=edge_labels, font_size=7)

plt.title("Red Bipartita Filtrada (Contratos ≥ 3)", fontsize=15)
plt.axis('off')  
plt.show()
No description has been provided for this image

3.3. Agrupamiento de comunidades¶

In [70]:
import matplotlib.pyplot as plt
import networkx as nx
import matplotlib.cm as cm

communities = list(nx.algorithms.community.greedy_modularity_communities(victoria))

plt.figure(figsize=(15, 10))

pos = nx.spring_layout(victoria, k=0.15, iterations=50, seed=42)  

colors = plt.colormaps['Set1'].colors

node_color_map = {}
for i, community in enumerate(communities):
    for node in community:
        node_color_map[node] = colors[i % len(colors)]  

node_colors = [node_color_map[node] for node in victoria.nodes()]

nx.draw_networkx_nodes(victoria, pos, node_color=node_colors, node_size=800, alpha=0.9)

nx.draw_networkx_edges(victoria, pos, width=1.5, alpha=0.5, edge_color="grey")

nx.draw_networkx_labels(victoria, pos, font_size=8, font_weight="bold")

plt.title("Red Bipartita con Detección de Comunidades", fontsize=15)
plt.axis('off') 

plt.show()
No description has been provided for this image

No es el mejor resultado, pero la vida continua...¶

3.4. Visualización interactiva de Comunidades¶

In [76]:
from pyvis.network import Network
import networkx as nx
import matplotlib.pyplot as plt 

comunidades = list(nx.algorithms.community.greedy_modularity_communities(victoria))

net = Network(height="750px", width="100%", notebook=True)

colors = plt.colormaps['Set1'].colors

for i, community in enumerate(comunidades):
    color = colors[i % len(colors)]  
    for node in community:
        net.add_node(str(node), label=str(node), color=color)  

for u, v, data in victoria.edges(data=True):
    weight = data.get('weight', 1)  
    net.add_edge(str(u), str(v), value=int(weight))  

net.repulsion(node_distance=300, spring_length=150)

net.show("red_interactiva.html")
Warning: When  cdn_resources is 'local' jupyter notebook has issues displaying graphics on chrome/safari. Use cdn_resources='in_line' or cdn_resources='remote' if you have issues viewing graphics in a notebook.
red_interactiva.html
Out[76]:

Podemos cambiar el color a las municipalidades¶

In [93]:
#Hacemos una lista primero
lista_distritos = lima_distritos.index.tolist()

print(lista_distritos)
['Ate', 'Barranco', 'Brena', 'Carabayllo', 'Chorrillos', 'Cieneguilla', 'Comas', 'El_Agustino', 'Independencia', 'La_Molina', 'La_Victoria', 'Lince', 'Los_Olivos', 'Lurigancho(Chosica)', 'Lurin', 'Magdalena_del_Mar', 'Miraflores', 'Pucusana', 'Puente_Piedra', 'Punta_Hermosa', 'Punta_Negra', 'Rimac', 'San_Borja', 'San_Isidro', 'San_Juan_de_Lurigancho', 'San_Juan_de_Miraflores', 'San_Luis', 'San_Martin_de_Porres', 'San_Miguel', 'Santa_Anita', 'Santa_Maria_del_Mar', 'Santa_Rosa', 'Santiago_de_Surco', 'Surquillo', 'Villa_El_Salvador', 'Villa_Maria_del_Triunfo', 'Paramonga', 'Pativilca', 'Supe', 'Cajatambo', 'Arahuay', 'Santa_Rosa_de_Quives', 'San_Vicente_de_Cañete', 'Asia', 'Cerro_Azul', 'Chilca', 'Imperial', 'Mala', 'Quilmana', 'Santa_Cruz_de_Flores', 'Huaral', 'Aucallama', 'Chancay', 'Ihuari', 'Santa_Cruz_de_Andamarca', 'Antioquia', 'Chicla', 'Huachupampa', 'Huanza', 'Huarochiri', 'Ricardo_Palma', 'San_Antonio', 'Santiago_de_Anchucaya', 'Santo_Domingo_de_los_Olleros', 'Surco(Huarochiri)', 'Huacho', 'Huaura', 'Sayan', 'Vegueta', 'Hongos', 'Omas', 'Quinches', 'Tauripampa', 'Tupe', 'Bellavista', 'La_Perla', 'La_Punta', 'Ventanilla', 'Mi_Peru']
In [89]:
from pyvis.network import Network
import networkx as nx
import matplotlib.pyplot as plt 

comunidades = list(nx.algorithms.community.greedy_modularity_communities(victoria))

lista_distritos = lima_distritos.index.tolist()

net = Network(height="750px", width="100%", notebook=True)

colors = plt.colormaps['Set1'].colors

distrito_color = 'blue'  # Cambia este color al que prefieras

for i, community in enumerate(comunidades):
    color = colors[i % len(colors)]  
    for node in community:
        if str(node) in lista_distritos:  
            net.add_node(str(node), label=str(node), color=distrito_color)  
        else:
            net.add_node(str(node), label=str(node), color=color)  

for u, v, data in victoria.edges(data=True):
    weight = data.get('weight', 1)  
    net.add_edge(str(u), str(v), value=int(weight))  

net.repulsion(node_distance=300, spring_length=150)

net.show("red_interactiva.html")
Warning: When  cdn_resources is 'local' jupyter notebook has issues displaying graphics on chrome/safari. Use cdn_resources='in_line' or cdn_resources='remote' if you have issues viewing graphics in a notebook.
red_interactiva.html
Out[89]:

3.5. Grado de los nodos¶

In [116]:
grado_nodos = dict(victoria.degree())
print(grado_nodos)
{'Ate': 18, 'Barranco': 7, 'Brena': 4, 'Carabayllo': 24, 'Chorrillos': 24, 'Cieneguilla': 3, 'Comas': 17, 'El_Agustino': 6, 'Independencia': 6, 'La_Molina': 2, 'La_Victoria': 3, 'Lince': 1, 'Los_Olivos': 19, 'Lurigancho(Chosica)': 29, 'Lurin': 10, 'Magdalena_del_Mar': 8, 'Miraflores': 6, 'Pucusana': 2, 'Puente_Piedra': 5, 'Punta_Hermosa': 6, 'Punta_Negra': 5, 'Rimac': 16, 'San_Borja': 10, 'San_Isidro': 19, 'San_Juan_de_Lurigancho': 8, 'San_Juan_de_Miraflores': 22, 'San_Luis': 7, 'San_Martin_de_Porres': 36, 'San_Miguel': 5, 'Santa_Anita': 14, 'Santa_Maria_del_Mar': 1, 'Santa_Rosa': 8, 'Santiago_de_Surco': 10, 'Surquillo': 3, 'Villa_El_Salvador': 3, 'Villa_Maria_del_Triunfo': 2, 'Paramonga': 2, 'Pativilca': 6, 'Supe': 5, 'Cajatambo': 2, 'Arahuay': 2, 'Santa_Rosa_de_Quives': 4, 'San_Vicente_de_Cañete': 20, 'Asia': 12, 'Cerro_Azul': 5, 'Chilca': 8, 'Imperial': 10, 'Mala': 15, 'Quilmana': 8, 'Santa_Cruz_de_Flores': 3, 'Huaral': 9, 'Aucallama': 6, 'Chancay': 9, 'Ihuari': 2, 'Santa_Cruz_de_Andamarca': 4, 'Antioquia': 2, 'Chicla': 2, 'Huachupampa': 3, 'Huanza': 2, 'Huarochiri': 1, 'Ricardo_Palma': 1, 'San_Antonio': 12, 'Santiago_de_Anchucaya': 2, 'Santo_Domingo_de_los_Olleros': 4, 'Surco(Huarochiri)': 1, 'Huacho': 33, 'Huaura': 3, 'Sayan': 5, 'Vegueta': 9, 'Hongos': 2, 'Omas': 2, 'Quinches': 2, 'Tauripampa': 4, 'Tupe': 2, 'Bellavista': 5, 'La_Perla': 4, 'La_Punta': 6, 'Ventanilla': 29, 'Mi_Peru': 9, 'ZRINCON_EIRL': 5, 'MIROVAL_SAC': 2, 'METACONTROL_SAC': 4, 'CORONEL_EJECUTORES': 3, 'WAR_SAC': 1, 'GIMAHU': 1, 'HUAYCHAOLA_SAC': 5, 'JAGIXA': 2, 'CONSTRUCTORA_DOLPHIN_SAC': 3, 'JD&HN': 1, 'JUSAL_INVERSIONES': 3, 'SIADEC_INGENIEROS_SAC': 7, 'ENMANUEL&LUCIANO': 1, 'VENTURO': 1, 'HELICONIAS_DEL_HUALLAGA': 1, 'LUCEMAR_EIRL': 4, 'CASCINA': 1, 'PJK': 2, 'NEBCAS_SAC': 3, 'LUMAYJE_SAC': 2, 'ESPINAR_SAC': 7, 'COSISE_CONSTRUCTORA': 4, 'INGEOBRAS_SAC': 3, 'GESTION&CONSTRUCCION_SAC': 4, 'CONSORCIO_MONTENEGRO': 2, 'JJP_SAC': 4, 'JJ_BYGGA': 1, 'COPER': 9, 'FKA': 1, 'COMAPORD_SAC': 2, 'ALTAS_CUMBRES': 1, 'JELY_CONTRATISTAS': 2, 'VACHAVEZ_SRL': 3, 'WCEX_EIRL': 3, 'EGUIZABAL': 1, 'AMIGARTE_PERU': 1, 'QUINAVAL': 1, 'GLOBAL_TRAKTOR': 1, 'FLAVIO': 2, 'WABS': 1, 'FALCON_SAC': 4, 'HELER': 1, 'OSERGEN_SAC': 2, 'YOMAR': 2, 'JACL': 1, 'COMPANY_SERVIS': 1, 'CONSTRUCTORA_TANOS': 2, 'CVV': 2, 'HT': 1, 'JHP': 1, 'JM_ARES': 1, 'AGREDA_GALLARDAY&JARA_SAC': 3, 'AMRO': 1, 'VSI': 1, 'DAMBEZ_COMPANY': 4, 'JARO': 4, 'BACA&TELLEZ': 1, 'NARDDY_EIRL': 2, 'JOMF_SRL': 3, 'GOLDEN': 1, 'GRUPO_V&ARQ': 1, 'C&C_SRL': 3, 'ALE_INGENIERIA&CONSTRUCCION': 2, 'TACTICAL_IT': 1, 'JFH': 1, 'AGS': 1, 'NANO': 1, 'VCP_CONSULTORES_Y_EJECUTORES': 3, 'EROVA_SAC': 4, 'MULTINEGOCIOS_KRISTEL': 1, 'LEON_CONTRATISTAS': 3, 'ALEJANDRO_CONTRATISTAS': 2, 'MARCOS_EIRL': 1, 'INVERSIONES&JUVE_CORP': 1, 'CONTRUCTORA_VALDIVIESO': 3, 'THIMAR_GROUP': 1, 'CCONST_J&L': 2, 'CODENSA_SAC': 3, '3G_CONSTRUCTORA': 2, 'XIANY_SAC': 3, 'INVERSIONES_MMG': 2, 'A&E_INVERSIONES': 1, 'GRUPO_JW': 1, 'ROAGA_SAC': 1, 'G&F_CONSTRUCTORA': 1, 'CORPORACION_JRO': 1, 'RASYR_CONSTRUCTORA': 2, 'INSERCO': 1, 'JAEC_CONTRATISTAS': 1, 'THE_MOON_CONTRATISTAS': 1, 'SABINA_CONTRATISTAS': 1, 'MONTALVO_CONSTRUCTORA': 3, 'BJL_CONSTRUCTORA': 1, 'GMP_SAC': 2, 'DASA_SAC': 1, 'EXAGATEC_SAC': 1, 'RANRA_SAC': 1, 'CH&G_SAC': 1, 'DUAL_DOOM': 1, 'M&S_PROYECTS': 5, 'MEJESA_SRL': 3, 'RIBAB_EIRL': 1, 'CAMEN_SAC': 1, 'SPACIOZ_SAC': 1, 'AJC_SAC': 2, 'MALLQUI_SAC': 3, 'CMM_SAC': 1, 'CORPORACION_JARA_Y_CHAVEZ': 3, 'CONINTEC_SRL': 3, 'IGYCSAC': 1, 'CORPORACION_LINARES_SAC': 5, 'SAUCE_GRANDE': 1, 'CONSORCIO_NARANJALES': 1, 'VIKAC_SAC': 1, 'CCOHIL_SAC': 1, 'CHEC-FUN_CONSTRUCTORA': 1, 'C&D_SAC': 1, 'MVR_SAC': 1, 'GRUPO_H&S': 1, 'GA_SERVICES_SOLUTIONS': 1, 'PROGEN_SAC': 1, 'INGENIERIA_Y_CONSTRUCCION GERAL': 1, 'EDCAVAR_SAC': 1, 'ICM_SAC': 1, 'JERUMI_EIRL': 1, 'CONCRETO_INKACON': 1, 'CHACHI_EIRL': 1, 'CARBAJAL_VICTOR': 1, 'SD_SAC': 1, 'CONTRUCTORA_FERRO': 1, 'M&N_SRL': 1, 'ARCONST_SAC': 4, 'NEPAL_SAC': 1, 'TROMMEL_SAC': 1, 'SUAREZ_MANUEL': 1, 'EDIRESA_SAC': 2, 'JF_CONSTRUCTORES_SAC': 3, 'MULTISERVICIOS_INMOBILIARIA_PAOLA': 1, 'JOVE_WILLIAM': 3, 'JOVE&JOVE_SAC': 2, 'G_Y_J_SAC': 1, 'SEASAP_SAC': 1, 'OVLV_SAC': 3, 'CONTRATISTAS_YOUNG_SAC': 2, 'Y_M_SAC': 4, 'MLM_SAC': 1, 'OUR_HOUSE_CONSTRUCTION': 1, 'LEXHIS_SAC': 1, 'INGCONS_EIRL': 2, 'HERCISA_SAC': 1, 'ASFALTOS_Y_PAVIMENTOS_SAC': 2, 'HIGH_CONSTRUCTIONS': 3, 'MULTINEGOCIOS_AARON_SAC': 1, 'INCOT_SAC': 1, 'CONSTRUCTORA_UPACA': 1, 'CONSTRUCTORA_PERU_TRACTOR': 1, 'DAED_SAC': 1, 'INVERSIONES_HILARIO_SAC': 1, 'UDEL_EIRL': 1, 'LEVAZ_SAC': 1, 'AG_GROUP_EIRL': 1, 'RASEC_EIRL': 1, 'JROTRI_EIRL': 2, 'HS_CONSTRUCTORA_INGENIEROS_SAC': 1, 'HUASCARAN_SAC': 2, 'TIERRA_SOL_SAC': 1, 'JA&DE_SA': 2, 'ROMAYSE_SAC': 2, 'OMZA_SAC': 1, 'MULTISERVIS_HH_EIRL': 1, 'VALENTINO_EIRL': 1, 'ALBEDI_SAC': 1, 'MILCORP_EIRL': 1, 'C_Y_R_SAC': 1, 'CRJ_SAC': 2, 'COMPANIA_GRA_CONSTRUCCIONES': 1, 'ACO_EIRL': 3, 'SANTO_DOMINGO_SAC': 2, 'CROS_PERU_SAC': 2, 'HA_CONSTRUCCION_SAC': 1, 'HB_SAC': 2, 'KUNAQ_SAC': 1, 'INVERSIONES_LIBERSCO': 1, 'PORFISA_CONTRATISTAS_GENERALES': 1, 'GRUPO_VITESSE_SAC': 2, 'CONTINENTAL_SAC': 4, 'LINGH_SAC': 1, 'CONSTRUCCIONES_METALICAS_TAE': 1, 'MJE_SAC': 1, 'CHAVISAN_EIRL': 1, 'VIALUSA_SAC': 1, 'A&L_SAC': 1, 'B&C_SA': 1, 'FAKECC_SAC': 1, 'MT_PROYECTOS_Y_OBRAS_SAC': 2, 'RGG_SAC': 1, 'NATHAN_EIRL': 1, 'CONSTRUCTORA_VANESSA_ORIETTA': 1, 'ICVSA_SA': 1, '1.0...201': 1, 'JBG_SAC': 1, 'MYVEC_SAC': 2, 'INVERSIONES_ALVAREZ_CONTRATISTAS_SAC': 1, 'INVERSIONES_BALY_EIRL': 1, 'CESPEDES_EDGAR': 1, 'SAM_BLASS_SAC': 1, 'CONSTRUCTORA_REVENGE_EIRL': 1, 'G_Y_R_SAC': 1, 'C&M_GARCIA_CONTRATISTAS_Y_CONSULTORES_SAC': 2, 'ALESOF_EIRL': 2, 'ISS_CONSTRUCTORA_SAC': 2, 'OUTPUT_SAC': 1, 'CONSTRUCTORA_Y_SERVICIOS_C&C_SRL': 1, 'AMERIKA_PROMASER_SRL': 1, 'CORPORACION_E_INVERSIONES_H&A_SAC': 2, 'INVERSIONES_Y_CONTRATISTAS_GRUPO_7_SAC': 4, 'CAMHARO_SAC': 3, 'CCODEINGESA': 1, 'CONSTRUCTORA_HERRERA_PERU_EIRL': 1, 'CONSTRUCTORA_MJR_SA': 1, 'CARBOZ_C_Y_M_EIRL': 1, 'V_Y_P_CONSTRUCTORA_Y_SERVICIOS_GENERALES_SAC': 1, 'E&G_CONTRATISTAS_GENERALES_SRL': 1, 'PROYECTOS_INDUSTRIALES_JR_SAC': 1, 'INVERSIONES_LUMI_EIRL': 1, 'CONSTRUCTORA_MTT_EIRL': 1, 'CONSTRUCTORA_GUTIERREZ&ASOCIADOS': 1, 'PEDRO_PABLO_MARTINEZ_INFANTES_EIRL': 3, 'SERBEMUZ_INDUSTRIALES&SERVICIOS_SAC': 2, 'CJV_CONTRATISTAS_GENERALES': 1, 'JJVL_CONTRATISTAS_GENERALES': 1, 'ALTAVISTA_INVERSIONES_GLOBALES_SAC': 1, 'DAHE_SERVICIOS_GENERALES': 1, 'ALTAS_CUMBRES_SAC': 0, 'CONSULTORES_Y_CONSTRUCTORA_MARKA_JIRKA': 1, 'CONSTRUCCIONES_&_CONSULTORES_ABIGATI': 1, 'FM_CONTRATISTAS_GENERALES': 1, 'LFX_SAC': 1, 'G_Y_L_MAGISTER_SALVADOR': 1, 'PACORQ_SRL': 1, 'RENCCO_CONTRATISTAS_GENERALES_SAC': 1, 'ABBANCE_COMPANY_SAC': 2, 'CONSTRUCCIONES_COMAFE_SAC': 1, 'CONSTRUCT_MABSA_INGEN_CONTRAT_GRALES': 1, 'CONSTRUCTORA_ANAID': 1, 'WALLALLO_CONSTRUCCION_E_INGENIERIA': 1, 'GMC_PROYECTOS_Y_CONSTRUCCIONES': 1, 'CONSTRUCTORA&CONTRATISTAS_GENERALES_SUSAN': 1, 'AC&V_INGENIEROS_CONTRATISTAS': 1, 'PRIMIAN_INVERSIONES': 1, 'CORPORACION_FRANMEGA': 1, 'ROHA_CONSTRUCTORES&CONSULTORES': 1, 'CONSTRUCTORA_MTL_EIRL': 1, 'CONSTRUCTORA_MVM_INGENIEROS': 1, 'COMUNE_CONSTRUCTORA_SAC': 1, 'ARQCON_CONSULTORES_Y_EJECUTORES': 1, 'GRUPO_MONTALVO_PRADA_SAC': 1, 'INGENIERIA_EN_CONSTRUCCION_SOLIS': 1, 'NEGOCIOS_M_Y_G_SERVICIOS_GENERALES': 1, 'CORPORACION_EL_ASPERO': 1, 'CORPORACION_HZ_CONTRATISTAS_GENERALES': 1, 'INVERSIONES_HERMANOS_CADILLO_MOTA': 3, 'INVERSIONES_A_Y_C_SAC': 1, 'CONTALMA_SRL': 1, 'MURCIA_EIRL': 1, 'ZAVALA_GROUP_SAC': 2, 'SERVICIOS_FERRETEROS_ALBERT': 2, 'PROMATEC_INGENIERIA&CONSTRUCCION': 1, 'CONSTRUCTORA_CWCM': 1, 'CJ&L_ATO_RENDIMIENTO_EN_CONSULTORIA_Y_EJECUTORIA_DE_INFRAESTRUCTURAS': 2, 'VM_ING_SAC': 3, 'G&I_ASOCIADOS_CONSULTORES': 2, 'CONSTRUCTORA_SEVMI_INVERSIONES': 1, 'CONSUR_CONSTRUCTORA_Y_CONSULTORIA': 1, 'KETU_SERVICIOS_Y_REPRESENTACIONES': 1, 'SALAZAR_Y_GALLO_CONTRATISTAS': 2, 'R_C_R_CONTRATISTAS_GENERALES': 1, 'JG_INGENIERIA_SERVICIOS_Y_PROYECTOS': 2, 'ENGINEER_ASSOCIATION_SAC': 1, 'DERC_CONSULTORES_Y_EJECUTORES': 1, 'CONSTRUCTORA_ALFA&BETA': 1, 'CORPORACION_ALHE_CONTRATISTAS_GENERALES': 3, 'CONSTRUCTORA_GALU': 1, 'INVERSIONES_MARVELZ': 1, 'ORIENCE_PERU_SAC': 1, '1.0...288': 1, 'INVERSIONES_Y_CONSTRUCCIONES_RUVIAT': 1, 'AP_CONTRATISTAS_GENERALES_SAC': 1, 'J_Y_S_SERVICIOS_GENERALES_SAC': 1, 'INVERSIONES_EJECUTORES_Y_CONSULTORES_DACA': 1, 'EMPRESA_MAQUISA_SAC': 2, 'CGG_MULTISERNING_GENERALES': 3, 'PORTICCONS_SAC': 1, 'JK_CONSULTORES_Y_CONSTRUCTORES': 1, 'TEGAM_SAC': 1, 'CONSTRUCCIONES_LORENA': 1, 'GRUPO_H_Y_S': 1, 'C&A_MACONI_INGENIEROS_EIRL': 1, 'EMPRESA_J&F_EIRL': 2, 'ESTANCIA_CASA_BLANCA_EIRL': 1, 'TOBE_SRL': 1, 'COFAB_EIRL': 1, 'GEL_SAC': 1, 'JL_SAC': 1, 'AQUIÑO_SRL': 1, 'V_Y_R_CONSTRUCTORA_SANCHEZ_SRL': 1, 'ISF_EIRLS': 1, 'GRUPO_FRANCO_SAC': 1, 'ROJU_EIRL': 1, 'ALUBE_EIRL': 1, 'TOKYO_SAC': 2, 'INGENIERIA&CONSULTORIA_EIRL': 1, 'FRAGON_SAC': 3, 'CS_SAC': 2, 'CONSULTORIA&INGENIERIA_PERUANA_SAC': 1, 'KALEPH_SAC': 2, 'LAURA_SAMANIEGO_SAC': 2, 'E&F_SAC': 1, 'KAJIRI_EIRL': 1, 'ALPAMAYO_SAC': 2, 'A&V_EIRL': 1, 'BONIFACIO_SAC': 1, 'PAMED_EIRL': 1, 'GEOX_EIRL': 1, 'FOREX_CONSTRUCTIONS_EIRL': 1, 'AI&CB_SRL': 1, 'MARGIL_SAC': 1, 'ICAT_SAC': 1, 'AZUR_SRL': 1, 'S&T_SRL': 1, 'REBOLLAR_SRL': 1, 'CODEING_SAC': 1, 'MICLEBY_SAC': 1, 'D&P_SAC': 1, 'ROMAC_EIRL': 1, 'ROKA_SAC': 2, 'INGECOL': 1, 'JFT_EIRL': 1, 'ADECON': 1, 'GHALIA_EIRL': 1, 'ARYSA_SAC': 1, 'JL_BARRIENTOS_SAC': 2, 'SIMON_HUERTA_ROJAS_SAC': 1, 'HEMSA_SRL': 1, 'AOC_SRL': 2, 'FASA_SAC': 1, 'AGRIBUSINESS_SAC': 1, 'CIVIC_EIRL': 1, 'GOE_EIRL': 1, 'PERUINSA_SAC': 1, 'CONSTRUCTORA_Y_CONSULTORA_DEL_PERU_SAC': 1, 'ZIBA_SAC': 1, 'C_Y_C_SAC': 1, 'HUMMINGTRIP_SAC': 1, 'GC_SAC': 1, 'P&J_EIRL': 1, 'LOA_WAUKIS_SAC': 1, 'CODECA_SAC': 1, 'MILENIUM_SAC': 1, 'ORDESA_A&C_SAC': 2, 'QUEVEDO_JIMENEZ_CESAR_AUGUSTO': 1, 'LUSA_SRL': 1, 'ARIS_SAC': 1, 'JE_EIRL': 1, 'CRANT_SAC': 1, 'MIDORI_SUR_SAC': 1, 'CONSTRUCTORA_Y_CONSULTORIAS_ARIAN_SAC': 1, 'PROYECTOS_CABA_ASOCIADOS_SAC': 1, 'PILLCO201_EIRL': 1, 'PILAR_DE_LA_CRUZ_SAC': 1, 'ALCO_CONSULTORES_Y_CONSTRUCTORES_GENERALES_SAC': 1, 'INGENIERIA_APLICADA_EN_SUPERVISION_SAC': 1, 'CONSTRUCTORA_CHOCOS_ESPINOZA_SRL': 1, 'PS&C_DE_VANGUARDIA_EIRL': 1, 'CONSORCIO_B&V_INGENIEROS_EMPRESA_INDIVIDUAL': 1, 'EL_ZETA_SAC': 1, 'CORPORACION_INGENIERIA&CONSULTORIA_EIRL': 1, 'GREEN_GOLD_SAC': 2, 'OBREGON_CONTRATISTAS_GENERALES_SAC': 2, 'TECNOMIN_DATA': 2, 'M_Y_W_VERTIZ_CARLOS_SAC': 1, 'EJECUTORES_Y_CONSULTRES_WVC_SAC': 1, 'CORPORACION_GRUPO_SOBRADO_SAC': 1, 'FERREMAR_PEREZ_SAC': 1, 'ARMAS_RODRIGUEZ_VICTOR': 2, 'CONSTRUCTORA_NEINCO_SAC': 1, 'CORPORACION_JESSKARSA_SAC': 1, 'CONSTRUCCIONES_E_INVERSIONES_KWT_SAC': 1, 'S&H_CONSTRUCTORA_SULQUITA_HUAMANI_SRL': 1, 'SERVIPROYECTOS_ALYMAR_SAC': 1, 'EMPRESA_CONSTRUCTORA_LOPEZ_SAC': 1, 'CONTRATISTAS_GENERALES_HUAURA_SRL': 1, 'COJAPRI_INGENIEROS_EIRL': 1, 'COINBISE_SAC': 1, 'CONZEL_SAC': 1, 'CORPORACION_ANDINA_YIRET_EIRL': 1, 'SAN_AGUSTIN_EIRL_CONTRATISTAS_GENERALES': 1, 'CORPORACION_DAGOBA_SAC': 1, "CONSTRUCTORA_Y_CORPORACION_D'GALLO_EIRL": 1, 'AMPER_SISTEMAS_SUCURSAL_PERU_SA': 1, 'ARES_SERVICIOS_GLOBALES_SAC': 1, 'CONSAJAK_CIX_SAC': 1, 'FEMACH_SAC': 1, 'EIFEL_CONSTRUCCIONES_Y_SERVICIOS_GENERALES_SAC': 1, 'DAIDARIUS_SAC': 1, 'INVERSIONES_MINERAS_TOROMIN_SAC': 1, 'CONSAGA_INGENIEROS_CONTRATISTAS_GENERALES_SRL': 1, 'TELEANDES_CONTRATISTAS_GENERALES_SAC': 1, 'TEINGECON_SAC': 1, 'GRUPO_HTS_SAC': 1, 'CORPORATION_TEKNY&RAN_EIRL': 1, 'CONSTRUCTORA_INMOBILIARIA_GOLD_SAC': 1, 'CONSTRUCTORA_GERED_SAC': 1, 'PSD_FORTALEZA_SAC': 1, 'CONSTRUCTORA_Y_SERVICIOS_GENERALES_A&R_SRL': 1, 'GRUPO_CONSTRUCTOR_HAZ_Y_HNOS_LA_SRL': 1, 'SERVICIOS_Y_CONSTRUCCION_VILLAVICENCIO_SAC': 1, 'COPCOGE_EIRL': 1, 'NYM_ARELLANO_CONSTRUCTOR_SAC': 1, 'DEREK_CONTRATISTAS_GENERALES_SAC': 1, 'GRUPO_ST_INGENIERIA&CONSTRUCCION_EIRL': 1, 'CVJ_CONTRATISTAS_GENERALES_SRL': 1, 'GELI_SAC': 1, "LOREN'S_SAC": 1, 'SAUCEDO_INGENIERIA_Y_CONSTRUCCION_SAC': 1, 'NFRC_EIRL': 1, 'REBECSA_SAC': 1, 'BECERRA_Y_BECERRA_CONSTRUCTORES_SAC': 1, 'SAENZ_CONSTRUCCTION_EMPRESA': 1, 'GRUPO_REMEC_SAC': 1, 'DICIESA_EIRL': 1, 'CONSTRUCTORA_NISSI_SAC': 1, 'SAMIR_CONTRATISTAS_GENERALES_SAC': 1, 'NEW_ACROPOLIS_SAC': 1, 'INVERSIONES_CAVIANDINA_SAC': 1, 'DAZER_CONSTRUCTION_SAC': 1, 'GRALAZ_SAC': 1, 'ECOTRAM_EIRL': 1, 'CORPORACION_INGENIERIA_Y_DESARROLLO_SAC': 1, 'W&W_CONSTRUCTORES_SAC': 1, 'GEOTEGG_SAC': 1, 'MAKI_ASOCIADOS_SAC': 1, 'COINVEFER_EIRL': 1, 'G&P_EL_ROBLE_SAC': 1}

Distribución de grados¶

In [119]:
import matplotlib.pyplot as plt

grados = [grado for _, grado in grado_nodos.items()]

plt.figure(figsize=(10, 6))
plt.hist(grados, bins=range(max(grados) + 2), align='left', color='lightblue', edgecolor='black')
plt.title('Distribución de Grado de los Nodos')
plt.xlabel('Grado')
plt.ylabel('Frecuencia')
plt.xticks(range(max(grados) + 1))
plt.show()
No description has been provided for this image

El grado de un nodo en una red representa el número de conexiones (o aristas) que tiene dicho nodo.

Paso 4: Exploración¶

In [142]:
#Vemos el tipo de red, si sale "True" es porque es una red bipartita
print(nx.is_bipartite(victoria))
True
In [146]:
#Contamos el número de nodos y aristas
num_nodes = len(victoria.nodes)
num_edges = len(victoria.edges)
print(f"Número de nodos: {num_nodes}, Número de aristas: {num_edges}")
Número de nodos: 523, Número de aristas: 646

4.1. Connectivity¶

In [155]:
#Para evaluar la conectividad de una red bipartita, hay que tener en cuenta que el concepto de conectividad puede diferir.

is_connected = nx.is_connected(victoria)  
print(f"¿Está conectada la red? {is_connected}")

if not is_connected:
    components = list(nx.connected_components(victoria)) 
    print(f"Número de componentes conectadas: {len(components)}")
    
    sizes = [len(c) for c in sorted(components, key=len, reverse=True)]
    print(f"Tamaño de cada componente: {sizes}")

isolates = list(nx.isolates(victoria))
print(f"Nodos aislados: {isolates}")
¿Está conectada la red? False
Número de componentes conectadas: 21
Tamaño de cada componente: [446, 7, 6, 6, 6, 5, 5, 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1]
Nodos aislados: ['ALTAS_CUMBRES_SAC']

Como se observa, la red no está conectada ('False') porque al menos un par de nodos en la red no tiene un camino que los una. Asimismo, el número de componentes conectados nos indica cuántos grupos de nodos están conectados entre sí. Por otro lado, el tamaño de cada componente se refiere a la cantidad de nodos que contiene cada uno de esos grupos conectados (esto nos ayuda a comprender cómo es que se distribuyen los nodos dentro de una red). Y, finalmente, los nodos aislados ('ALTAS_CUMBRES_SAC') son aquellos que no están conectados con ningún otro.

4.2. Distance¶

4.2.1. Diámetro de la Red¶

In [163]:
import networkx as nx

largest_bipartite_nodes = max(nx.connected_components(victoria), key=len)

victoria_largest = victoria.subgraph(largest_bipartite_nodes)

diameter = nx.diameter(victoria_largest)
print(f"Diámetro de la red bipartita: {diameter}")
Diámetro de la red bipartita: 12

El diámetro de una red bipartita es la longitud máxima del camino más corto entre todos los pared de nodos en la red.

4.2.2. Geodesias¶

In [190]:
geodesics = dict(nx.all_pairs_shortest_path_length(victoria))

MatrixGeo = [[geodesics.get(n, {}).get(m) for m in victoria.nodes] for n in victoria.nodes]

MatrixGeo_DF = pd.DataFrame(MatrixGeo, index=victoria.nodes, columns=victoria.nodes)

print(MatrixGeo_DF)
                       Ate  Barranco  Brena  Carabayllo  Chorrillos  \
Ate                    0.0       4.0    4.0         2.0         4.0   
Barranco               4.0       0.0    4.0         4.0         4.0   
Brena                  4.0       4.0    0.0         2.0         2.0   
Carabayllo             2.0       4.0    2.0         0.0         2.0   
Chorrillos             4.0       4.0    2.0         2.0         0.0   
...                    ...       ...    ...         ...         ...   
W&W_CONSTRUCTORES_SAC  3.0       5.0    5.0         3.0         3.0   
GEOTEGG_SAC            3.0       5.0    5.0         3.0         3.0   
MAKI_ASOCIADOS_SAC     3.0       5.0    5.0         3.0         3.0   
COINVEFER_EIRL         3.0       5.0    5.0         3.0         3.0   
G&P_EL_ROBLE_SAC       3.0       5.0    5.0         3.0         3.0   

                       Cieneguilla  Comas  El_Agustino  Independencia  \
Ate                            2.0    2.0          2.0            6.0   
Barranco                       4.0    2.0          4.0            4.0   
Brena                          4.0    2.0          2.0            4.0   
Carabayllo                     2.0    2.0          2.0            4.0   
Chorrillos                     4.0    2.0          2.0            4.0   
...                            ...    ...          ...            ...   
W&W_CONSTRUCTORES_SAC          3.0    3.0          5.0            7.0   
GEOTEGG_SAC                    3.0    3.0          5.0            7.0   
MAKI_ASOCIADOS_SAC             3.0    3.0          5.0            7.0   
COINVEFER_EIRL                 3.0    3.0          5.0            7.0   
G&P_EL_ROBLE_SAC               3.0    3.0          5.0            7.0   

                       La_Molina  ...  INVERSIONES_CAVIANDINA_SAC  \
Ate                          NaN  ...                         3.0   
Barranco                     NaN  ...                         5.0   
Brena                        NaN  ...                         5.0   
Carabayllo                   NaN  ...                         3.0   
Chorrillos                   NaN  ...                         3.0   
...                          ...  ...                         ...   
W&W_CONSTRUCTORES_SAC        NaN  ...                         2.0   
GEOTEGG_SAC                  NaN  ...                         2.0   
MAKI_ASOCIADOS_SAC           NaN  ...                         2.0   
COINVEFER_EIRL               NaN  ...                         2.0   
G&P_EL_ROBLE_SAC             NaN  ...                         2.0   

                       DAZER_CONSTRUCTION_SAC  GRALAZ_SAC  ECOTRAM_EIRL  \
Ate                                       3.0         3.0           3.0   
Barranco                                  5.0         5.0           5.0   
Brena                                     5.0         5.0           5.0   
Carabayllo                                3.0         3.0           3.0   
Chorrillos                                3.0         3.0           3.0   
...                                       ...         ...           ...   
W&W_CONSTRUCTORES_SAC                     2.0         2.0           2.0   
GEOTEGG_SAC                               2.0         2.0           2.0   
MAKI_ASOCIADOS_SAC                        2.0         2.0           2.0   
COINVEFER_EIRL                            2.0         2.0           2.0   
G&P_EL_ROBLE_SAC                          2.0         2.0           2.0   

                       CORPORACION_INGENIERIA_Y_DESARROLLO_SAC  \
Ate                                                        3.0   
Barranco                                                   5.0   
Brena                                                      5.0   
Carabayllo                                                 3.0   
Chorrillos                                                 3.0   
...                                                        ...   
W&W_CONSTRUCTORES_SAC                                      2.0   
GEOTEGG_SAC                                                2.0   
MAKI_ASOCIADOS_SAC                                         2.0   
COINVEFER_EIRL                                             2.0   
G&P_EL_ROBLE_SAC                                           2.0   

                       W&W_CONSTRUCTORES_SAC  GEOTEGG_SAC  MAKI_ASOCIADOS_SAC  \
Ate                                      3.0          3.0                 3.0   
Barranco                                 5.0          5.0                 5.0   
Brena                                    5.0          5.0                 5.0   
Carabayllo                               3.0          3.0                 3.0   
Chorrillos                               3.0          3.0                 3.0   
...                                      ...          ...                 ...   
W&W_CONSTRUCTORES_SAC                    0.0          2.0                 2.0   
GEOTEGG_SAC                              2.0          0.0                 2.0   
MAKI_ASOCIADOS_SAC                       2.0          2.0                 0.0   
COINVEFER_EIRL                           2.0          2.0                 2.0   
G&P_EL_ROBLE_SAC                         2.0          2.0                 2.0   

                       COINVEFER_EIRL  G&P_EL_ROBLE_SAC  
Ate                               3.0               3.0  
Barranco                          5.0               5.0  
Brena                             5.0               5.0  
Carabayllo                        3.0               3.0  
Chorrillos                        3.0               3.0  
...                               ...               ...  
W&W_CONSTRUCTORES_SAC             2.0               2.0  
GEOTEGG_SAC                       2.0               2.0  
MAKI_ASOCIADOS_SAC                2.0               2.0  
COINVEFER_EIRL                    0.0               2.0  
G&P_EL_ROBLE_SAC                  2.0               0.0  

[523 rows x 523 columns]
In [232]:
#reemplazamos los 'NA' por 0
MatrixGeo_DF.fillna(0, inplace=True)
print(MatrixGeo_DF)
                       Ate  Barranco  Brena  Carabayllo  Chorrillos  \
Ate                    0.0       4.0    4.0         2.0         4.0   
Barranco               4.0       0.0    4.0         4.0         4.0   
Brena                  4.0       4.0    0.0         2.0         2.0   
Carabayllo             2.0       4.0    2.0         0.0         2.0   
Chorrillos             4.0       4.0    2.0         2.0         0.0   
...                    ...       ...    ...         ...         ...   
W&W_CONSTRUCTORES_SAC  3.0       5.0    5.0         3.0         3.0   
GEOTEGG_SAC            3.0       5.0    5.0         3.0         3.0   
MAKI_ASOCIADOS_SAC     3.0       5.0    5.0         3.0         3.0   
COINVEFER_EIRL         3.0       5.0    5.0         3.0         3.0   
G&P_EL_ROBLE_SAC       3.0       5.0    5.0         3.0         3.0   

                       Cieneguilla  Comas  El_Agustino  Independencia  \
Ate                            2.0    2.0          2.0            6.0   
Barranco                       4.0    2.0          4.0            4.0   
Brena                          4.0    2.0          2.0            4.0   
Carabayllo                     2.0    2.0          2.0            4.0   
Chorrillos                     4.0    2.0          2.0            4.0   
...                            ...    ...          ...            ...   
W&W_CONSTRUCTORES_SAC          3.0    3.0          5.0            7.0   
GEOTEGG_SAC                    3.0    3.0          5.0            7.0   
MAKI_ASOCIADOS_SAC             3.0    3.0          5.0            7.0   
COINVEFER_EIRL                 3.0    3.0          5.0            7.0   
G&P_EL_ROBLE_SAC               3.0    3.0          5.0            7.0   

                       La_Molina  ...  INVERSIONES_CAVIANDINA_SAC  \
Ate                          0.0  ...                         3.0   
Barranco                     0.0  ...                         5.0   
Brena                        0.0  ...                         5.0   
Carabayllo                   0.0  ...                         3.0   
Chorrillos                   0.0  ...                         3.0   
...                          ...  ...                         ...   
W&W_CONSTRUCTORES_SAC        0.0  ...                         2.0   
GEOTEGG_SAC                  0.0  ...                         2.0   
MAKI_ASOCIADOS_SAC           0.0  ...                         2.0   
COINVEFER_EIRL               0.0  ...                         2.0   
G&P_EL_ROBLE_SAC             0.0  ...                         2.0   

                       DAZER_CONSTRUCTION_SAC  GRALAZ_SAC  ECOTRAM_EIRL  \
Ate                                       3.0         3.0           3.0   
Barranco                                  5.0         5.0           5.0   
Brena                                     5.0         5.0           5.0   
Carabayllo                                3.0         3.0           3.0   
Chorrillos                                3.0         3.0           3.0   
...                                       ...         ...           ...   
W&W_CONSTRUCTORES_SAC                     2.0         2.0           2.0   
GEOTEGG_SAC                               2.0         2.0           2.0   
MAKI_ASOCIADOS_SAC                        2.0         2.0           2.0   
COINVEFER_EIRL                            2.0         2.0           2.0   
G&P_EL_ROBLE_SAC                          2.0         2.0           2.0   

                       CORPORACION_INGENIERIA_Y_DESARROLLO_SAC  \
Ate                                                        3.0   
Barranco                                                   5.0   
Brena                                                      5.0   
Carabayllo                                                 3.0   
Chorrillos                                                 3.0   
...                                                        ...   
W&W_CONSTRUCTORES_SAC                                      2.0   
GEOTEGG_SAC                                                2.0   
MAKI_ASOCIADOS_SAC                                         2.0   
COINVEFER_EIRL                                             2.0   
G&P_EL_ROBLE_SAC                                           2.0   

                       W&W_CONSTRUCTORES_SAC  GEOTEGG_SAC  MAKI_ASOCIADOS_SAC  \
Ate                                      3.0          3.0                 3.0   
Barranco                                 5.0          5.0                 5.0   
Brena                                    5.0          5.0                 5.0   
Carabayllo                               3.0          3.0                 3.0   
Chorrillos                               3.0          3.0                 3.0   
...                                      ...          ...                 ...   
W&W_CONSTRUCTORES_SAC                    0.0          2.0                 2.0   
GEOTEGG_SAC                              2.0          0.0                 2.0   
MAKI_ASOCIADOS_SAC                       2.0          2.0                 0.0   
COINVEFER_EIRL                           2.0          2.0                 2.0   
G&P_EL_ROBLE_SAC                         2.0          2.0                 2.0   

                       COINVEFER_EIRL  G&P_EL_ROBLE_SAC  
Ate                               3.0               3.0  
Barranco                          5.0               5.0  
Brena                             5.0               5.0  
Carabayllo                        3.0               3.0  
Chorrillos                        3.0               3.0  
...                               ...               ...  
W&W_CONSTRUCTORES_SAC             2.0               2.0  
GEOTEGG_SAC                       2.0               2.0  
MAKI_ASOCIADOS_SAC                2.0               2.0  
COINVEFER_EIRL                    0.0               2.0  
G&P_EL_ROBLE_SAC                  2.0               0.0  

[523 rows x 523 columns]

La siguiente tabla nos muestra las distancias más cortas entre todos los pares de nodos en la red.

4.2.3. Tabla de Frecuencia: Geodesias¶

In [194]:
import numpy as np
frequency_table = pd.DataFrame(np.unique(MatrixGeo_DF.values, return_counts=True), index=['valor', 'freq']).T.set_index('valor')
print(frequency_table)
          freq
valor         
0.0    74793.0
1.0     1292.0
2.0     9662.0
3.0    11238.0
4.0    58346.0
5.0    21090.0
6.0    66700.0
7.0     8964.0
8.0    18496.0
9.0     1174.0
10.0    1666.0
11.0      52.0
12.0      56.0

Nos señala cuántas veces cada distancia aparece entre los pared de nodos. Un alto número de frecuencias para distancias cortas indica que muchos nodos están conectados de manera cercana, mientras que frecuencias bajas en distancias largas sugieren que esos caminos son menos comunes.

4.2.4. Matriz de Alcance¶

In [196]:
MatrixReach_DF = (MatrixGeo_DF > 0).astype(int)
print(MatrixReach_DF)
                       Ate  Barranco  Brena  Carabayllo  Chorrillos  \
Ate                      0         1      1           1           1   
Barranco                 1         0      1           1           1   
Brena                    1         1      0           1           1   
Carabayllo               1         1      1           0           1   
Chorrillos               1         1      1           1           0   
...                    ...       ...    ...         ...         ...   
W&W_CONSTRUCTORES_SAC    1         1      1           1           1   
GEOTEGG_SAC              1         1      1           1           1   
MAKI_ASOCIADOS_SAC       1         1      1           1           1   
COINVEFER_EIRL           1         1      1           1           1   
G&P_EL_ROBLE_SAC         1         1      1           1           1   

                       Cieneguilla  Comas  El_Agustino  Independencia  \
Ate                              1      1            1              1   
Barranco                         1      1            1              1   
Brena                            1      1            1              1   
Carabayllo                       1      1            1              1   
Chorrillos                       1      1            1              1   
...                            ...    ...          ...            ...   
W&W_CONSTRUCTORES_SAC            1      1            1              1   
GEOTEGG_SAC                      1      1            1              1   
MAKI_ASOCIADOS_SAC               1      1            1              1   
COINVEFER_EIRL                   1      1            1              1   
G&P_EL_ROBLE_SAC                 1      1            1              1   

                       La_Molina  ...  INVERSIONES_CAVIANDINA_SAC  \
Ate                            0  ...                           1   
Barranco                       0  ...                           1   
Brena                          0  ...                           1   
Carabayllo                     0  ...                           1   
Chorrillos                     0  ...                           1   
...                          ...  ...                         ...   
W&W_CONSTRUCTORES_SAC          0  ...                           1   
GEOTEGG_SAC                    0  ...                           1   
MAKI_ASOCIADOS_SAC             0  ...                           1   
COINVEFER_EIRL                 0  ...                           1   
G&P_EL_ROBLE_SAC               0  ...                           1   

                       DAZER_CONSTRUCTION_SAC  GRALAZ_SAC  ECOTRAM_EIRL  \
Ate                                         1           1             1   
Barranco                                    1           1             1   
Brena                                       1           1             1   
Carabayllo                                  1           1             1   
Chorrillos                                  1           1             1   
...                                       ...         ...           ...   
W&W_CONSTRUCTORES_SAC                       1           1             1   
GEOTEGG_SAC                                 1           1             1   
MAKI_ASOCIADOS_SAC                          1           1             1   
COINVEFER_EIRL                              1           1             1   
G&P_EL_ROBLE_SAC                            1           1             1   

                       CORPORACION_INGENIERIA_Y_DESARROLLO_SAC  \
Ate                                                          1   
Barranco                                                     1   
Brena                                                        1   
Carabayllo                                                   1   
Chorrillos                                                   1   
...                                                        ...   
W&W_CONSTRUCTORES_SAC                                        1   
GEOTEGG_SAC                                                  1   
MAKI_ASOCIADOS_SAC                                           1   
COINVEFER_EIRL                                               1   
G&P_EL_ROBLE_SAC                                             1   

                       W&W_CONSTRUCTORES_SAC  GEOTEGG_SAC  MAKI_ASOCIADOS_SAC  \
Ate                                        1            1                   1   
Barranco                                   1            1                   1   
Brena                                      1            1                   1   
Carabayllo                                 1            1                   1   
Chorrillos                                 1            1                   1   
...                                      ...          ...                 ...   
W&W_CONSTRUCTORES_SAC                      0            1                   1   
GEOTEGG_SAC                                1            0                   1   
MAKI_ASOCIADOS_SAC                         1            1                   0   
COINVEFER_EIRL                             1            1                   1   
G&P_EL_ROBLE_SAC                           1            1                   1   

                       COINVEFER_EIRL  G&P_EL_ROBLE_SAC  
Ate                                 1                 1  
Barranco                            1                 1  
Brena                               1                 1  
Carabayllo                          1                 1  
Chorrillos                          1                 1  
...                               ...               ...  
W&W_CONSTRUCTORES_SAC               1                 1  
GEOTEGG_SAC                         1                 1  
MAKI_ASOCIADOS_SAC                  1                 1  
COINVEFER_EIRL                      0                 1  
G&P_EL_ROBLE_SAC                    1                 0  

[523 rows x 523 columns]

La matriz de alcance, la cual asume los valores de 0 y 1, nos indica si es que existe o no un camino entre un par de nodos.

4.2.5. Conectividad¶

In [198]:
import networkx as nx

# Verificar si la red bipartita está conectada
is_connected = nx.is_connected(victoria)
print(f"¿Está la red bipartita conectada? {is_connected}")

# Obtener componentes conectados
if not is_connected:
    components = list(nx.connected_components(victoria))
    print(f"Número de componentes conectados: {len(components)}")
¿Está la red bipartita conectada? False
Número de componentes conectados: 21

4.3. Density¶

In [202]:
density = nx.density(victoria) 
print(f"Densidad de la red bipartita: {density}")
Densidad de la red bipartita: 0.004732496721683773

La densidad en nuestra red bipartita nos sugiere que la red tiene muy pocas conexiones en comparación con lo que sería posible, lo que indica una estructura de red poco conectada y posiblemente dispersa.

4.4. Medidas de Centralidad¶

4.4.1. Centralidad de Grado¶

In [208]:
degree_centrality = nx.degree_centrality(victoria)

El grado de un nodo es la cantidad de conexiones (o aristas) que tiene con otros nodos en la red. Un alto grado indica que el nodo está muy conectado y, por lo tanto, podría ser considerado importante o influente en la red. Un bajo grado sugiere que el nodo tiene pocas conexiones y podría ser menos relevante en términos de conectividad.

4.4.2. Centralidad de Cercanía¶

In [211]:
closeness_centrality = nx.closeness_centrality(victoria)

La centralidad de cercanía mide qué tan cerca está un nodo de todos los demás nodos en la red. Un alto valor de cercanía significa que un nodo puede acceder rápidamente a otros nodos en la red, lo que puede ser beneficioso para la difusión de información o recursos. Un bajo valor de cercanía sugiere que el nodo está relativamente lejos de otros, lo que podría limitar su capacidad de interactuar eficientemente dentro de la red.

4.4.3. Centralidad de Intermediación¶

In [214]:
betweenness_centrality = nx.betweenness_centrality(victoria)

La centralidad de intermediación mide cuántas veces un nodo actúa como intermediario en el camino más corto entre otros nodos. Un alto valor de intermediación indica que un nodo tiene un papel crucial en conectar diferentes partes de la red. Un bajo valor de intermediación sugiere que el nodo no desempeña un papel importante en la conexión de otros nodos y, por lo tanto, puede ser menos influyente en términos de control o mediación en la red.

4.4.5. Compilación de Medidas de Centralidad¶

In [243]:
actorMeasures = pd.concat([pd.DataFrame.from_dict(degree_centrality, orient='index', columns=['Degree']),
                            pd.DataFrame.from_dict(closeness_centrality, orient='index', columns=['Closeness']),
                            pd.DataFrame.from_dict(betweenness_centrality, orient='index', columns=['Betweenness'])], axis=1)

#Visualizamos los datos
print(actorMeasures)
                         Degree  Closeness  Betweenness
Ate                    0.034483   0.206847     0.057678
Barranco               0.013410   0.209822     0.020619
Brena                  0.007663   0.185960     0.006775
Carabayllo             0.045977   0.214085     0.060433
Chorrillos             0.045977   0.223152     0.119075
...                         ...        ...          ...
W&W_CONSTRUCTORES_SAC  0.001916   0.172123     0.000000
GEOTEGG_SAC            0.001916   0.172123     0.000000
MAKI_ASOCIADOS_SAC     0.001916   0.172123     0.000000
COINVEFER_EIRL         0.001916   0.172123     0.000000
G&P_EL_ROBLE_SAC       0.001916   0.172123     0.000000

[523 rows x 3 columns]

4.4.6. Visualización de Medidas de Centralidad¶

In [221]:
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(10, 10))

ax.scatter(actorMeasures.Closeness, actorMeasures.Degree, s=1000*actorMeasures.Betweenness,
           c=100*actorMeasures.Betweenness, cmap=plt.get_cmap('YlOrRd'), alpha=0.6)

valsForAnnotate = zip(actorMeasures.index, actorMeasures.Closeness, actorMeasures.Degree)
for name, coordX, coordY in valsForAnnotate:
    ax.annotate(name, (coordX, coordY), alpha=0.5)

plt.title("Centralidad (tamaño y color para Intermediación)", y=-0.1)
plt.xlabel("Cercanía")
plt.ylabel("Grado")
plt.show()
No description has been provided for this image

Lo mejoramos¶

In [254]:
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(12, 12))

scatter = ax.scatter(
    actorMeasures.Closeness,
    actorMeasures.Degree,
    s=1000 * actorMeasures.Betweenness,
    c=actorMeasures.Betweenness,
    cmap='YlOrRd',
    alpha=0.6,
    edgecolor='black',
    linewidth=0.5
)

valsForAnnotate = zip(actorMeasures.index, actorMeasures.Closeness, actorMeasures.Degree)

for name, coordX, coordY in valsForAnnotate:
    if actorMeasures.Betweenness.loc[name] > actorMeasures.Betweenness.quantile(0.98):  # Top 2%
        ax.annotate(name, (coordX, coordY), fontsize=8, alpha=0.7)

plt.title("Centralidad (tamaño y color para Intermediación)", fontsize=16, y=1.02)
plt.xlabel("Cercanía", fontsize=14)
plt.ylabel("Grado", fontsize=14)

cbar = plt.colorbar(scatter)
cbar.set_label('Centralidad de Intermediación', fontsize=12)
cbar.ax.tick_params(labelsize=10)

plt.grid(True, linestyle='--', alpha=0.5)
plt.xlim(left=0)  
plt.ylim(bottom=0)  

plt.show()
No description has been provided for this image